当前位置: 首页 > news >正文

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)

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

	rect = cv2.minAreaRect(cnt)targetColor = roi_colortargetThickness = 1targetColor = (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 = 15cv2.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)

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

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) % 360length = getDistance(p1, p2) // 4if (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)

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

	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)

在这里插入图片描述

def slopeAngle(p1, p2):slope  = (p2[1] - p1[1]) / (p2[0] - p1[0])theta  = np.arctan(slope)degree = int(theta * 57.29577) % 360return thetadef lineByPoint(photo, pp, theta, length, color, thickness):if True:p1 = (int(pp[0] - length * math.cos(theta)),int(pp[1] - length * math.sin(theta)))
     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 = 15theta = slopeAngle(p1, p2)lineByPoint(photo, center, theta, crossLength, targetColor, targetThickness)theta = slopeAngle(p2, p3)lineByPoint(photo, center, theta, crossLength, targetColor, targetThickness)

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

Automatic Mask

if True:matrix = np.array(cnt)for i in range(len(matrix)):matrix[i][0][0] = matrix[i][0][0] - xmatrix[i][0][1] = matrix[i][0][1] - ymask = 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)

在这里插入图片描述

http://www.lryc.cn/news/171696.html

相关文章:

  • 【AD】【规则设置】设置四层板
  • Linux安装JDK1.8并配置环境变量
  • 面向面试知识--MySQL数据库与索引
  • portainer + portainer/agent
  • C# 截取字符串
  • FOXBORO FBM233 P0926GX控制脉冲模块
  • MySQL性能优化——MYSQL执行流程
  • Django:四、Djiango如何连接使用MySQL数据库
  • LeetCode 热题 100(八):贪心。121. 买卖股票的最佳时机、45. 跳跃游戏 II
  • 第N个数字
  • 【适用于电力系统和音频系统】计算信号的总谐波失真 (THD)(Matlab代码实现)
  • kubernetes(k8s)PVC
  • Android ANR问题触发机制
  • 解决jupyter找不到虚拟环境的问题
  • Unity丨移动相机朝向目标并确定目标在摄像机可视范围内丨摄像机注释模型丨摄像机移动丨不同尺寸模型优化丨
  • 排序算法:归并排序(递归和非递归)
  • 数据可视化
  • Go并发可视化解释 – select语句
  • http的网站进行访问时候自动跳转至https
  • realloc
  • Windows AD域使用Linux Samba
  • Scrapy+Selenium自动化获取个人CSDN文章质量分
  • 【Android Framework系列】第15章 Fragment+ViewPager与Viewpager2相关原理
  • typeof的作用
  • 性能测试 —— Tomcat监控与调优:status页监控
  • Ubuntu 安装 CUDA 与 CUDNN GPU加速引擎
  • pdf文件太大如何处理?教你pdf压缩简单方法
  • Nacos使用教程(二)——nacos注册中心(1)
  • 蓝桥杯2023年第十四届省赛真题-买瓜--C语言题解
  • R语言进行孟德尔随机化+meta分析(1)---meta分析基础