python - 如何通过 Python OpenCV 单击检测到的边缘?
问题描述
使用以下代码,我可以检测矩形的边缘,但现在我想点击矩形的每个边缘?我怎么能做到这一点?
import numpy as np
import cv2
import matplotlib.pyplot as plt
import matplotlib
import win32api
matplotlib.rcParams["savefig.dpi"] = 400 # to get high resolution
img = cv2.imread('1.png');
plt.imshow( img )
plt.title('Original Image')
plt.show()
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# Apply Canny edge detection method on the image
edges = cv2.Canny(gray,75,150,apertureSize = 3)
plt.imshow(edges )
plt.title('My Image edges')
plt.show()
#lines = cv2.HoughLines(edges,1,np.pi/180, 200)
lines = cv2.HoughLinesP(edges,1,np.pi/180, 150)
print(lines)
解决方案
You can use the following:
if (lines.any() == True):
for line in lines:
x1,y1, _, _ = line[0]
cv2.Rectangle(img,(x1,y1),(x1+3,y1+3),(0,255,0),3)
cv2.imshow('image', img)
cv2.waitKey(0)
cv2.destroyAllWindow()
this code will go throw all the edges one by one
推荐阅读
- java - 如何使用 rxjava 和 rxandroid 在图像视图上设置可绘制对象
- css - 从 Angular 8 更新到 Angular 9 后,“ng generate component”会生成一个 .css 文件而不是 .scss
- azure - Nop-Commerce MarketPlace Azure 首次部署问题
- c - pthread_join 在处理多个客户端时无法分叉 TCP 服务器
- javascript - 使用 n:m 相关对象上的关联来处理错误
- java - 在 HashMap 中获取最小的可用键 (>= 1)
- mongodb - 将 $in 用于 mongodb 中嵌入式 DBRef 对象上的 id 字段
- javascript - 线性渐变在 Outlook 中不起作用
- javascript - 如何根据鼠标位置触发可变字体?
- three.js - 如何在three.js中从法线点创建splats?