• OpenCV Series : Target Box Outline Border


    在这里插入图片描述
    角点

    P1      [0]     (255, 000, 000)
    P2      [1]     (000, 255, 000)
    P3      [2]     (000, 000, 255)
    P4      [3]     (000, 000, 000)
    
    • 1
    • 2
    • 3
    • 4

    在这里插入图片描述
    垂直矩形框

    	rect = cv2.minAreaRect(cnt)
    	targetColor = roi_color
    	targetThickness = 1
    	targetColor = (255, 255, 255)
    	if lineVerbose:
    		if True:
    		   cv2.line(photo,  (x, y), (x+w//4, y), targetColor, targetThickness)
    		   cv2.line(photo,  (x, y), (x, y+h//4), targetColor, targetThickness)
    		
    		   cv2.line(photo,  (x+3*w//4, y), (x+w, y), targetColor, targetThickness)
    		   cv2.line(photo,  (x+w, y), (x+w, y+h//4), targetColor, targetThickness)
    		
    		   cv2.line(photo,  (x, y+h), (x+w//4, y+h), targetColor, targetThickness)
    		   cv2.line(photo,  (x, y+h), (x, y+3*h//4), targetColor, targetThickness)
    		
    		   cv2.line(photo,  (x+w, y+h), (x+3*w//4, y+h), targetColor, targetThickness)
    		   cv2.line(photo,  (x+w, y+h), (x+w, y+3*h//4), targetColor, targetThickness)
    		
    		   crossLength = 15
    		   cv2.line(photo,  (x+w//2-crossLength, y+h//2), (x+w//2+crossLength, y+h//2), targetColor, targetThickness)
    		   cv2.line(photo,  (x+w//2, y+h//2-crossLength), (x+w//2, y+h//2+crossLength), targetColor, targetThickness)
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22

    在这里插入图片描述
    在这里插入图片描述
    倾斜矩形框

    def lineByAngle(photo, p1, p2, length, color, thickness):
        slope = 0 + (p2[1] - p1[1]) / (p2[0] - p1[0])
        theta = np.arctan(slope)
        degree = int(theta * 57.29577) % 360
    
        length = getDistance(p1, p2) // 4
    
        if (p2[0] < p1[0]):
            pp = (
                int(p1[0] - length * np.cos(theta)),
                int(p1[1] - length * np.sin(theta))
            )
        else:
            pp = (
                int(p1[0] + length * np.cos(theta)),
                int(p1[1] + length * np.sin(theta))
            )
        cv2.line(photo,  p1, pp, color, thickness)
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19

    在这里插入图片描述
    几何关键点

    	if True:
    	    cv2.circle(photo, p1, 1, roi_red, 5)
    	    cv2.circle(photo, p2, 1, roi_red, 5)
    	    cv2.circle(photo, p3, 1, roi_red, 5)
    	    cv2.circle(photo, p4, 1, roi_red, 5)
    	
    	    center = (int((p1[0] + p3[0]) / 2), int((p2[1] + p4[1]) / 2))
    	    cv2.circle(photo, center, 1, roi_green, 5)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    在这里插入图片描述

    def slopeAngle(p1, p2):
        slope  = (p2[1] - p1[1]) / (p2[0] - p1[0])
        theta  = np.arctan(slope)
        degree = int(theta * 57.29577) % 360
        return theta
    
    def lineByPoint(photo, pp, theta, length, color, thickness):
        if True:
            p1 = (
                int(pp[0] - length * math.cos(theta)),
                int(pp[1] - length * math.sin(theta))
            )
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
         center = (int((p1[0] + p3[0]) / 2), int((p2[1] + p4[1]) / 2))
         if not True:
             cv2.circle(photo, p1, 1, roi_blue,  5)
             cv2.circle(photo, p2, 1, roi_green, 5)
             cv2.circle(photo, p3, 1, roi_red,   5)
             cv2.circle(photo, p4, 1, roi_black, 5)
             cv2.circle(photo, center, 1, roi_green, 5)
         if True:
             crossLength = 15
             theta = slopeAngle(p1, p2)
             lineByPoint(photo, center, theta, crossLength, targetColor, targetThickness)
             theta = slopeAngle(p2, p3)
             lineByPoint(photo, center, theta, crossLength, targetColor, targetThickness)
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

    在这里插入图片描述
    在这里插入图片描述

    Automatic Mask

    if True:
        matrix = np.array(cnt)
        for i in range(len(matrix)):
            matrix[i][0][0] = matrix[i][0][0] - x
            matrix[i][0][1] = matrix[i][0][1] - y
        mask = np.zeros(characteristic.shape[:2], dtype=np.uint8)
        mask = cv2.fillPoly(mask, [matrix], 255)
        cv2.imshow('Mask', mask)
    
        image = cv2.bitwise_and(characteristic, characteristic, mask = mask)
        image = stretch(image)
        cv2.imshow('Masked', image)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    在这里插入图片描述

  • 相关阅读:
    html静态网页-求爱表白代码(爱心特效代码520)
    10月 kaggle-酶稳定性预测(群链接)
    .net在使用存储过程中IN参数的拼接方案,使用Join()方法
    AdsPower RPA一些编写思路(进阶)
    Linux进程控制--程序替换
    免密码方式获取Hive元数据
    华为1000人校园实验记录
    基础算法--理解递归
    树莓派(四)树莓派外设开发基础篇
    小分子化合物库/FDA 上市库-NC 高分解析
  • 原文地址:https://blog.csdn.net/unix2linux/article/details/132869377