我试图用OpenCV扫描我项目中的工作区,OpenCV是棋盘的形式。为了做到这一点,我已经采取了以下步骤,也提到了以下网站
但我得到的结果是在扭曲的形式,这是由于噪音在原来的照片,我从相机。你知道吗
那么,有没有办法去除原始图片中由于相机引起的噪声,最终得到不失真的输出呢。你知道吗
我所说的无失真输出是指工作场所的黑白框形式,就像我们在棋盘上看到的那样。你知道吗
为了您的考虑,我还附上以下东西
a)我用于处理的原始图像 b) 输出完成处理后得到的图像
我使用的代码片段如下
image = cv2.imread(arg["image"])
(h, w, d) = image.shape
#Resize image
ratio = image.shape[0]/500.0
orig = image.copy()
image = imutils.resize(image,height = 500)
#Find edge, blur it
gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
gray = cv2.GaussianBlur(gray,(3,3),0)
edged = cv2.Canny(gray,75,200)
# find the contours in the edged image, keeping only the
# largest ones, and initialize the screen contour
cnts = cv2.findContours(edged.copy(),cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)
cnts = imutils.grab_contours(cnts)
cnts = sorted(cnts,key = cv2.contourArea, reverse = True)[:5]
#loop over the contours
for c in cnts:
#approximate the contour
peri = cv2.arcLength(c,True)
approx = cv2.approxPolyDP(c,0.02*peri, True)
#if our approximated contour has four points, then we
# can assume that we have found our screen
if len(approx) == 4:
screenCnt = approx
break
# show the contour (outline) of the piece of paper
cv2.drawContours(image,[screenCnt],-1,(0,255),2)
cv2.imshow("Outline",image)
#apply the four point transform to obtain a top-down
#view of original image
warped = four_point_transform(orig,screenCnt.reshape(4,2)*ratio)
#convert the wrapped image to grayscle, then threshold it
#to give it that 'black and white ' paper effect
warped = cv2.cvtColor(warped,cv2.COLOR_BGR2GRAY)
T = threshold_local(warped,11,offset =10,method = "gaussian")
warped = (warped >T).astype("uint8")*255
#show the original and scanned images
print("STEP3: Apply perspective transform")
cv2.imshow("Original",imutils.resize(orig,height=650))
cv2.imshow("Scanned",imutils.resize(warped,height=650))
cv2.imwrite("OutputImage.png",imutils.resize(warped,height=650))
如果您需要任何其他信息,请通知我。你知道吗
非常感谢:)
原始图像
处理后输出图像
这不是噪音,而是混叠,因为你的分辨率比你想检测的方块小得多。增加正方形的大小或相机的分辨率。 你必须遵循Nyquist Rate,像素的大小必须至少是半个正方形。你知道吗
相关问题 更多 >
编程相关推荐