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)
相关推荐
程序小旭2 小时前
机器视觉基础—双目相机
计算机视觉·双目相机
qzhqbb2 小时前
基于统计方法的语言模型
人工智能·语言模型·easyui
冷眼看人间恩怨3 小时前
【话题讨论】AI大模型重塑软件开发:定义、应用、优势与挑战
人工智能·ai编程·软件开发
2401_883041083 小时前
新锐品牌电商代运营公司都有哪些?
大数据·人工智能
AI极客菌4 小时前
Controlnet作者新作IC-light V2:基于FLUX训练,支持处理风格化图像,细节远高于SD1.5。
人工智能·计算机视觉·ai作画·stable diffusion·aigc·flux·人工智能作画
阿_旭4 小时前
一文读懂| 自注意力与交叉注意力机制在计算机视觉中作用与基本原理
人工智能·深度学习·计算机视觉·cross-attention·self-attention
王哈哈^_^4 小时前
【数据集】【YOLO】【目标检测】交通事故识别数据集 8939 张,YOLO道路事故目标检测实战训练教程!
前端·人工智能·深度学习·yolo·目标检测·计算机视觉·pyqt
Power20246665 小时前
NLP论文速读|LongReward:基于AI反馈来提升长上下文大语言模型
人工智能·深度学习·机器学习·自然语言处理·nlp
数据猎手小k5 小时前
AIDOVECL数据集:包含超过15000张AI生成的车辆图像数据集,目的解决旨在解决眼水平分类和定位问题。
人工智能·分类·数据挖掘
好奇龙猫5 小时前
【学习AI-相关路程-mnist手写数字分类-win-硬件:windows-自我学习AI-实验步骤-全连接神经网络(BPnetwork)-操作流程(3) 】
人工智能·算法