锐化图像以检测标记为“X”的边缘/线条。在纸上的对象 [英] sharpen image to detect edges/lines in a stamped "X" object on paper

查看:131
本文介绍了锐化图像以检测标记为“X”的边缘/线条。在纸上的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用python& OpenCV的。我的目标是检测用覆盆子pi相机拍摄的图像中的X形片。该项目是我们有预先印制的井字板,每次将新件放在板上(带有油墨印章)时,必须对板进行成像。然后输出说明什么类型的件(如果有的话)在井字板的哪个部分。



在这里,我在图像中检测到绿线:





如你所见,X形件似乎并不容易检测。某些邮票上只有一行被看到。



以下是过滤后边缘检测的样子:





我检测X的方法成形件是在每个部分检查任何具有非水平/垂直斜率的线。我的问题是X形邮票不是完美的线条;因此,我的代码很难在线上。



我尝试应用非锐化滤波器,使用直方图均衡,并且只使用灰度进行边缘检测。这些都没有在任何X形件中检测到超过1条线。



大致我在做什么:

  #sharpen image using blur和非锐化方法
gaussian_1 = cv2.GaussianBlur(image,(9,9),10.0)
unsharp_image = cv2.addWeighted(image,1.5,gaussian_1,-0.5,0,image)
#apply过滤器查找标记片段,灰度图上的直方图均衡化
hist_eq = cv2.equalizeHist(unsharp_image)
#edge detection(input,threshold1,threshold2,size_for_sobel_operator)
edges = cv2.Canny( hist_eq,50,150,apertureSize = 3)
#find lines(edges,min_pixels,min_degrees,min_intersections,lineLength,LineGap)
lines = cv2.HoughLinesP(edges,1,np.pi / 180,50, minLineLength,maxLineGap)

我只是单独将这个应用于电路板的9个部分中的每个部分,但这并不重要。



TLDR:
如何制作我的图像以使我的线条清脆和锐利?我想知道我可以用什么来制作一个标记为X的几行。

解决方案

你可以用


I'm using python & opencv. My goal is to detect "X" shaped pieces in an image taken with a raspberry pi camera. The project is that we have pre-printed tic-tac-toe boards, and must image the board every time a new piece is laid onto the board (with ink stamps). Then the output says what type of piece, if any, is in what section of the tic-tac-toe board.

Here, I have the lines I have detected in the image in green:

As you can see, the "X" shaped pieces seems to not be easily detected. Only one line on some of the stamps gets "seen."

Here's what the edge detection looks like after the filters:

My method for detecting the "X" shaped piece is to check in each section for any lines with a non-horizontal/vertical slope. My problem is that the "X" shaped stamps are not perfect lines; thus, my code hardly picks up on the lines.

I have tried applying an unsharp filter, using histogram equalization, and just using grayscale into edge detection. None of these have detected more than 1 line in any "X" shaped piece.

Roughly what I am doing:

#sharpen image using blur and unsharp method
gaussian_1 = cv2.GaussianBlur(image, (9,9), 10.0)
unsharp_image = cv2.addWeighted(image, 1.5, gaussian_1, -0.5, 0, image)
#apply filter to find stamp pieces, histogram equalization on greyscale
hist_eq = cv2.equalizeHist(unsharp_image)
#edge detection (input,threshold1,threshold2,size_for_sobel_operator)
edges = cv2.Canny(hist_eq,50,150,apertureSize = 3)
#find lines (edges,min_pixels,min_degrees,min_intersections,lineLength,LineGap)
lines = cv2.HoughLinesP(edges,1,np.pi/180,50,minLineLength,maxLineGap)

Only I'm applying this to each of the 9 sections of the board individually, but that's not really important.

TLDR: How can I make my image so that my lines are "crisp" and sharp? I would like to know what I can use to make a stamped "X" look like a few lines.

解决方案

You can try Canny edge detector with Otsu's robust method for determining the dual threshold value.

im = cv2.imread('9WJTNaZ.jpg', 0)
th, bw = cv2.threshold(im, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)
edges = cv2.Canny(im, th/2, th)

Then you can use

  • convexity defects of the contours

or

  • the area of the filled contour to the area of the bounding box of the contour

to differentiate the cross marks from circles.

This is what I get when I apply Canny to your image.

这篇关于锐化图像以检测标记为“X”的边缘/线条。在纸上的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆