我想在下面的问题纸上使用4点变换。根据代码,它应该选择具有4个点的最长轮廓(这是环绕纸张的绿色近似矩形)并围绕该轮廓扭曲页面。但是当我执行4点变换时,它给出了奇怪的结果
当我使用过滤器对图像进行预处理时,它没有这个问题。有没有办法在OpenCV中应用这样的过滤器
cnts=
cv2.findContours(edged.copy(),cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
cnts = imutils.grab_contours(cnts)
docCnt = None
ok=False
# ensure that at least one contour was found
if len(cnts) > 0:
# sort the contours according to their size in
# descending order
cnts = sorted(cnts, key=cv2.contourArea, reverse=True)
# loop over the sorted 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 we have found the paper
if len(approx) == 4:
docCnt = approx
ok=True
break
paper = four_point_transform(image, docCnt.reshape(4, 2))
These contours were obtained with the filtered image
目前没有回答
相关问题 更多 >
编程相关推荐