OpenCV Series : Target Box Outline Border


角点

c 复制代码
P1      [0]     (255, 000, 000)
P2      [1]     (000, 255, 000)
P3      [2]     (000, 000, 255)
P4      [3]     (000, 000, 000)


垂直矩形框

c 复制代码
	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)



倾斜矩形框

c 复制代码
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)


几何关键点

c 复制代码
	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)
c 复制代码
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))
        )
c 复制代码
     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)


Automatic Mask

c 复制代码
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)
相关推荐
88号技师43 分钟前
2024年12月一区SCI-加权平均优化算法Weighted average algorithm-附Matlab免费代码
人工智能·算法·matlab·优化算法
IT猿手44 分钟前
多目标应用(一):多目标麋鹿优化算法(MOEHO)求解10个工程应用,提供完整MATLAB代码
开发语言·人工智能·算法·机器学习·matlab
88号技师44 分钟前
几款性能优秀的差分进化算法DE(SaDE、JADE,SHADE,LSHADE、LSHADE_SPACMA、LSHADE_EpSin)-附Matlab免费代码
开发语言·人工智能·算法·matlab·优化算法
2301_764441331 小时前
基于python语音启动电脑应用程序
人工智能·语音识别
HyperAI超神经1 小时前
未来具身智能的触觉革命!TactEdge传感器让机器人具备精细触觉感知,实现织物缺陷检测、灵巧操作控制
人工智能·深度学习·机器人·触觉传感器·中国地质大学·机器人智能感知·具身触觉
galileo20161 小时前
转化为MarkDown
人工智能
一勺汤1 小时前
YOLO11改进-注意力-引入多尺度卷积注意力模块MSCAM
yolo·目标检测·计算机视觉·改进·魔改·yolov11·yolov11改进
说私域2 小时前
私域电商逆袭密码:AI 智能名片小程序与商城系统如何梦幻联动
人工智能·小程序
请站在我身后2 小时前
复现Qwen-Audio 千问
人工智能·深度学习·语言模型·语音识别
love you joyfully3 小时前
目标检测与R-CNN——paddle部分
人工智能·目标检测·cnn·paddle