From c21d4e37968d92d0f4cd052c8252994e75601ac7 Mon Sep 17 00:00:00 2001
From: ming-xiao-yuan <55716320+ming-xiao-yuan@users.noreply.github.com>
Date: Mon, 27 Jul 2020 10:50:52 -0400
Subject: [PATCH] Premiere commit de armor-colour

---
 .../armor_color/hough_transform.py            | 56 +++++++++++++++++++
 1 file changed, 56 insertions(+)
 create mode 100644 robots-at-robots/research/robots_at_robots/armor_color/hough_transform.py

diff --git a/robots-at-robots/research/robots_at_robots/armor_color/hough_transform.py b/robots-at-robots/research/robots_at_robots/armor_color/hough_transform.py
new file mode 100644
index 0000000..4a8d72e
--- /dev/null
+++ b/robots-at-robots/research/robots_at_robots/armor_color/hough_transform.py
@@ -0,0 +1,56 @@
+# 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
-- 
GitLab