I am new to coding and not that familiar with working with opencv and python but right now, I have this progress with my project where I have detected each wire. I was able to do this by coding the hsv color range of each wire, mask and label them with their respective color.
So what I wanted to ask help is how do I match and say that the sequence is correct.
Note that my input is coming from a real-time video camera and I’ll be getting the frame and compare it with a reference image which contains the correct color sequence.
As we can see, from the reference image, the last wire should be gray, but the input has an orange wire. Therefore, the output frame labeled the last wire of orange as “incorrect wire”
Here’s my sample code where red wire is detected.
import cv2 import numpy as np import imutils frame = cv2.imread('Template.jpg') frame = cv2.resize(frame, (450,450)) hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) ***#Identifying HSV Range*** ***#RED*** lr = np.array([0, 150, 0],np.uint8) ur = np.array ([3, 255, 255],np.uint8) ***#THRESHOLDING*** red_mask = cv2.inRange(hsv, lr, ur) resultr = cv2.bitwise_and(frame,frame, mask=red_mask) ***#CONTOURING*** contours_r = cv2.findContours(red_mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) contours_r = imutils.grab_contours(contours_r) for c in contours_r: area_r= cv2.contourArea(c) if area_r>2000: M = cv2.moments(c) cx = int(M['m10']/M['m00']) cy = int(M['m01']/M['m00']) cv2.circle(frame, (cx,cy), 4, (0, 255, 0), -1) #Defines the size of the white circle cv2.putText(frame, 'Red', (cx-20, cy-20), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0,255,0), 1) cv2.imshow("Result", np.hstack([frame, resultr])) cv2.waitKey(0)