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)
相关推荐
余炜yw41 分钟前
【LSTM实战】跨越千年,赋诗成文:用LSTM重现唐诗的韵律与情感
人工智能·rnn·深度学习
莫叫石榴姐1 小时前
数据科学与SQL:组距分组分析 | 区间分布问题
大数据·人工智能·sql·深度学习·算法·机器学习·数据挖掘
弗锐土豆1 小时前
工业生产安全-安全帽第二篇-用java语言看看opencv实现的目标检测使用过程
java·opencv·安全·检测·面部
如若1231 小时前
利用 `OpenCV` 和 `Matplotlib` 库进行图像读取、颜色空间转换、掩膜创建、颜色替换
人工智能·opencv·matplotlib
YRr YRr2 小时前
深度学习:神经网络中的损失函数的使用
人工智能·深度学习·神经网络
ChaseDreamRunner2 小时前
迁移学习理论与应用
人工智能·机器学习·迁移学习
Guofu_Liao2 小时前
大语言模型---梯度的简单介绍;梯度的定义;梯度计算的方法
人工智能·语言模型·矩阵·llama
我爱学Python!2 小时前
大语言模型与图结构的融合: 推荐系统中的新兴范式
人工智能·语言模型·自然语言处理·langchain·llm·大语言模型·推荐系统
果冻人工智能2 小时前
OpenAI 是怎么“压力测试”大型语言模型的?
人工智能·语言模型·压力测试
日出等日落2 小时前
Windows电脑本地部署llamafile并接入Qwen大语言模型远程AI对话实战
人工智能·语言模型·自然语言处理