杂货账单:
由于图像的顶部和底部的某些部分缺少最大轮廓,即无法裁剪主钞票。该代码在完整的账单图像的情况下运行良好,但无法处理丢失的顶点图像。
代码:
imgContours = img.copy() # COPY ORIGNAL IMAGE
imgBigContour = img.copy() # COPY ORIGNAL IMAGE
_, contours,_ = cv2.findContours(imgThreshold, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) # FIND ALL CONTOURS
cv2.drawContours(imgContours, contours, -1, (0, 255, 0), 10) # DRAW ALL DETECTED CONTOURS
# FIND THE BIGGEST COUNTOUR
biggest, maxArea = utlis.biggestContour(contours) # FIND THE BIGGEST CONTOUR
if biggest.size != 0:
biggest=utlis.reorder(biggest)
cv2.drawContours(imgBigContour, biggest, -1, (0, 255, 0), 20) # DRAW THE BIGGEST CONTOUR
imgBigContour = utlis.drawRectangle(imgBigContour,biggest,2)
pts1 = np.float32(biggest) # PREPARE POINTS FOR WARP
pts2 = np.float32([[0, 0],[widthImg, 0], [0, heightImg],[widthImg, heightImg]]) # PREPARE POINTS FOR WARP
matrix = cv2.getPerspectiveTransform(pts1, pts2)
imgWarpColored = cv2.warpPerspective(img, matrix, (widthImg, heightImg))