- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个可以弯曲电线的机器人设备,我尝试通过查看所需的真实角度测量值来测量弯曲是否成功。
我的想法是检测电线并为电线的每一段画一条线,之后它就变成了一个小三角问题。但我找不到绘制和获取这些线的坐标的方法。
我对图像处理非常陌生,所以请原谅我的粗俗术语。
最佳答案
这看起来是一个有趣的问题。我们可以利用弯曲线材和未弯曲线材的垂直边缘强度不同的事实。当我们使用垂直 Sobel 滤波器对其进行滤波时,未弯曲的导线将返回更高的值。
y方向sobel滤波器的结果
通过提取不同强度的区域( Blob )来提取弯曲和未弯曲的线。
Stronger edge will correspond to the unbent wire.
Weaker edge will correspond to the bent wire.
通过opencv Blob 分析函数minRectArea,我们可以获得 Blob 的角度、大小和中心位置。
角度值 w.r.t.水平线
Unbent Wire : 3.94 degree
Bent Wire : 21.37 degree
以下是用于获取上述结果的代码:
import cv2
import numpy as np
import matplotlib.pyplot as plt
# extract blob with largest area
def get_best_blob(blobs):
best_blob = None
best_size = 0
for i,blob in enumerate(blobs):
rot_rect = cv2.minAreaRect(blob)
(cx,cy),(sx,sy),angle = rot_rect
if sx * sy >best_size :
best_blob = rot_rect
best_size = sx * sy
return best_blob
def draw_blob_rect(frame,blob,color):
box = cv2.boxPoints(blob)
box = np.int0(box)
frame = cv2.drawContours(frame,[box],0,color,1)
return frame
def process():
image = cv2.imread("wire.png")
# Change to grayscale
gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
# Reduce size for speed
gray = cv2.resize(gray,(0,0),fx=0.5,fy=0.5)
# Extract wire region
_ , thresh = cv2.threshold(gray,100,255,cv2.THRESH_BINARY_INV)
# morphology kernel
kernel = np.array((
[1, 1, 1],
[1, 1, 1],
[1, 1, 1]
), dtype="int")
# Get y-edges
dy = cv2.Sobel(thresh,cv2.CV_32F,0,1,ksize=21)
# remove negative values
dy = dy * dy
# Normalize it to 255
cv2.normalize(dy,dy,norm_type=cv2.NORM_MINMAX,alpha=255)
dy = dy.astype('uint8')
# Extract relevant information
# Stronger edge is the original part
# Weaker edge is the bended part
_ , strong = cv2.threshold(dy,0.95 * 255,255,cv2.THRESH_BINARY)
_ , mid = cv2.threshold(dy,0.5 * 255,255,cv2.THRESH_BINARY)
# Morphological closing to remove holes
strong_temp = cv2.dilate(strong,kernel, iterations=5)
strong = cv2.erode(strong_temp,kernel, iterations=5)
# remove the strong part from the mid
mid = cv2.subtract(mid,strong_temp)
# Morphological closing to remove holes
mid_temp = cv2.dilate(mid,kernel, iterations=5)
mid = cv2.erode(mid_temp,kernel, iterations=5)
# find the blobs for each bin image
_,strong_blobs,_ = cv2.findContours(strong,cv2.RETR_EXTERNAL ,cv2.CHAIN_APPROX_SIMPLE)
_,mid_blobs,_ = cv2.findContours(mid,cv2.RETR_EXTERNAL ,cv2.CHAIN_APPROX_SIMPLE)
# get the blob with the largest area
best_strong = get_best_blob(strong_blobs)
best_mid = get_best_blob(mid_blobs)
# print the angle
print( "strong_angle",90 + best_strong[2])
print( "mid_angle",90 + best_mid[2])
# Draw the segmented Box region
display_frame = cv2.cvtColor(gray,cv2.COLOR_GRAY2BGR)
display_frame = draw_blob_rect(display_frame,best_strong,(0,0,255))
display_frame = draw_blob_rect(display_frame,best_mid,(0,255,255))
# draw result
cv2.imshow("display_frame",display_frame)
cv2.imshow("mid",mid)
cv2.imshow("strong",strong)
cv2.imshow("image",image)
cv2.imshow("dy",dy)
cv2.waitKey(0)
if __name__=='__main__':
process()
关于python - 使用 OpenCV 测量弯曲线的真实角度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59733180/
我正在使用我的简单 PHP 验证码算法 ( http://www.source.ofitall.com/devel/captcha.php ),我一直在努力尝试调整它以使其更具吸引力和更易于阅读,谷歌
我正在 android 中实现一个 ListView ,它看起来就像这样并滚动 我一直在通过在我的适配器的 getView 中设置膨胀行的布局参数来做到这一点,但由此引发的问题是 ListView 变
我正在尝试使用 flex 和 bison 创建一个计算器,它可以进行一组操作(结果分配给变量)。计算器使用存储器来存储这些变量。当我通过终端(标准输入键盘)进行此计算时,一切正常。但是,当我尝试使用文
我的Flex应用程序中有数据网格,我使用Arraycollection绑定(bind)数据网格(使用remoteobject方法调用从java类获取数据)。现在我正在数据网格中执行添加/编辑/删除,我
是否可以制作弯曲或拱形形状的矩形。这是我的 jsfiddle https://jsfiddle.net/dibyendu/y8pthz2x/ 。我想使用 d3 使雷达图轴上的这些矩形成为弧形/曲线 最
我有一张代表某个区域海拔的图像。但是制造它的无人机不一定走直线(尽管图像总是矩形的)。我还有每 20 厘米生成的 gps 坐标。 如何“弯曲”这个矩形图像(曲线/马赛克),使其代表无人机实际经过的弯曲
我经历了How to curve the top of a UIView Controller in Swift 并发表看法。它附在下面。我想从我的 View 中删除该背景色。我在 Storyboar
任何人都可以帮助弯曲 View 以达到以下效果。我正在使用自定义 View 组,我想操纵 Canvas 来实现以下效果,谁能帮帮我。 谢谢 最佳答案 你需要知道: Camera Matrix 这是一个
我尝试绘制一些 3D 正方形(在 iPhone 上使用 OpenGL)并让它们旋转,现在它们看起来像一个球体。 http://i618.photobucket.com/albums/tt265/Loy
我想创建一个 div,它是一个按钮,它包含一个国旗的图片和一个国家的 abv,我已经将一些代码放入我想要的内容中,但这不是 Bootstrap 的方式,我'我正在努力解决这个问题,以及如何使用 boo
现在我正在用一系列 View 填充 UIScrollView。需要扭曲 View 以使 UIScrollView 看起来像旋转木马。换句话说,当用户滚动时,它需要像一个圆圈。我以前从未做过类似的事情,
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我是一名优秀的程序员,十分优秀!