python绘制圆角正方形_具有圆角的矩形的Python OpenCV透视校正

下面的脚本(从pyimagesearch.com修改)尝试更正扫描卡的透视图以旋转和裁剪图像。我有完成转换的最终代码,但在此之前绘制的边界矩形没有按预期运行。这是原始图片:

1620

码:# import the necessary packages

from skimage.filters import threshold_local

import numpy as np

import cv2

import imutils

# load the image and compute the ratio of the old height

# to the new height, clone it, and resize it

image = cv2.imread('cards/red8.jpg')

ratio = image.shape[0] / 500.0

orig = image.copy()

image = imutils.resize(image, height = 500)

# convert the image to grayscale, blur it, and find edges

# in the image

gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

gray = cv2.GaussianBlur(gray, (5, 5), 0)

blur = cv2.GaussianBlur(gray,(1,1),1000)

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_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

cnts = cnts[0] if imutils.is_cv2() else cnts[1]

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

cv2.drawContours(image, [screenCnt], -1, (0, 255, 0), 2)

被绘制的盒子的输出似乎被圆角抛弃并抛出透视校正,但是偏离了卡片的直边的一小部分。

1620

我能做些什么来得到一个适当的边界矩形来计算弯曲的边缘?

谢谢!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值