Skip to content
Snippets Groups Projects
Commit c21d4e37 authored by ming-xiao-yuan's avatar ming-xiao-yuan
Browse files

Premiere commit de armor-colour

parent f9bc7450
No related branches found
No related tags found
No related merge requests found
# pseudo-code to recognize color without any ai
# 1. load image and xml
# 2. get position from xml
# 2.1 crop to make it smaller (less data to process)
# 3. RGB colorspace ---> HSV colorspace
# 3.1 could apply Hough transform
# 4. get threshold and play around with it
import cv2
import numpy as np
# read image as black and white
img = cv2.imread("g.jpg")
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
# detectiion of edges as array
edges = cv2.Canny(gray,100,200,apertureSize = 3)
# origibal image : 50 x 124 x 3
# edges : 50 x 124
x = len(img)
y = len(img[0])
print(x)
print(y)
colored_edges = []
for i in range(x):
row = []
for j in range(y):
if (j < 0.3 * y or j > 0.7 * y) and (i > 0.3 * x and i < 0.7 * x):
if edges[i][j] == 255:
row.append(img[i][j])
else:
row.append([0,0,0])
else:
row.append([0,0,0])
colored_edges.append(row)
hsv = cv2.cvtColor(np.float32(np.asarray(colored_edges)), cv2.COLOR_BGR2HSV)
color = 0
nbpixel = 0
for i in range(x):
for j in range(y):
if hsv[i][j][2] != 0:
hsv[i][j][1] = 100000
hsv[i][j][2] = 100000
v = hsv[i][j][0]
nbpixel += 1
if v > 180:
color += 360 - v
else:
color += v
print(color/nbpixel)
newimage = cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR)
cv2.imwrite("red_out.jpg", newimage)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment