当前位置:网站首页>Reading of double pointer instrument panel (II) - Identification of dial position

Reading of double pointer instrument panel (II) - Identification of dial position

2022-06-22 14:50:00 Jialanxiang

The contents of this chapter : Dial position identification and position fixation

Upper dial :

analysis :

1. The dial is round , There are multiple circular interferences in the whole frame of video , Including the small circle in the center of the pointer , A large circle and a small circle on the outside of the dial and the circle outside the screenshot .

2. Circle Recognition itself involves a lot of computation , Will take up a lot of resources

solve :

1. Circular dial standard identification

gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)  #  Convert to gray channel 
A, binary = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU) #  Two valued 

circles = cv2.HoughCircles(
        binary, cv2.HOUGH_GRADIENT, 2, 1000, param1=100, param2=100, minRadius=10, maxRadius=5000) #  Hoff identification     
    if circles is not None:  #  If a circle is recognized 
        for circle in circles[0]:
            #   Get the coordinates and radius of the circle 
            x = int(circle[0])
            y = int(circle[1])
            r = int(circle[2])
            MX1 = x - r
            MX2 = x + r
            MY1 = y - r
            MY2 = y + r
            JDMX1 = 0

            if MX1 < 0:
                JDMX1 = -MX1
                MX1 = MX1 - MX1
                print(1)
            if MX2 < 0:
                MX2 = MX2 - MX2
                print(2)
            if MY1 < 0:
                JDMY1 = -MY1
                MY1 = MY1 - MY1
                print(3)
            if MY2 < 0:
                MY2 = MY2 - MY2
                print(4)
            draw(MY1, MY2, MX1, MX2)

def draw(MY1, MY2, MX1, MX2):
    while (True):
        ret, frame = cap.read()
        maxTable = frame[MY1: MY2, MX1: MX2]  #  Cut out the square of the identified circle 
        a, b, c, d = msk(maxTable, x, y)
        # cv2.imshow('maxTable', maxTable)
        cv2.circle(frame, (x, y), r, (255, 255, 255), 3)  #  Mark circle 
        cv2.circle(frame, (x, y), 3, (255, 255, 0), -1)  #  Mark the center of the circle 

2. Use the first calculated position of the center of the circle and the radius of the circle to intercept , Make the circular position fixed , Subsequent operations are analyzed at the intercepted location

原网站

版权声明
本文为[Jialanxiang]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206220924142225.html