- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我无法使用 cv2.approxPolyDP()
绘制形状的完整轮廓。
我得到以下结果:
但我想要这样的输出:
这是我的代码:
import cv2
im = cv2.imread('C:\Python27\Test\Targets\s1.jpg') # read picture
imgray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY) # BGR to grayscale
ret, thresh = cv2.threshold(imgray, 200, 255, cv2.THRESH_BINARY)
countours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
epsilon = 0.1 * cv2.arcLength(countours[0], True)
approx = cv2.approxPolyDP(countours[0], epsilon, True)
cv2.drawContours(im, approx, -1, (0, 255, 0), 3)
cv2.imshow("Contour", im)
cv2.waitKey(0)
cv2.destroyAllWindows()
最佳答案
cv2.CHAIN_APPROX_SIMPLE
去除所有冗余点并压缩轮廓,从而节省内存。如果您传递给 findContours()
函数 cv2.CHAIN_APPROX_NONE
参数而不是 cv2.CHAIN_APPROX_SIMPLE
,您的问题将得到解决。您的代码应更改如下:
_, countours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE,
cv2.CHAIN_APPROX_NONE)
关于python - 在 python 中使用 cv2.approxPolyDP() 绘制轮廓,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41576815/
#include "opencv2/highgui/highgui.hpp" #include "opencv2/imgproc/imgproc.hpp" #include #include #i
您好,我正在研究有关轮廓的学校项目。一切正常,直到我尝试使用 approxPolyDP,这导致我的 VS2012 抛出此消息:hugh.exe 中 0x000007FEFD0E940D 处未处理的异常
我想用这个蒙版创建一些多边形: 图片 1 - 面具 所以我用 openCV findcontours() 创建了这些轮廓: 图片 2 - 轮廓 创建多边形时,我得到这些多边形: 图 3 - 多边形 如
我想用线段链来近似平滑线。 OpenCV 3.4中的cv2.approxPolyDP在闭合曲线的情况下取得了不错的效果。 原点闭合曲线: 近似闭合曲线: 但是在开曲线的情况下,cv2.approxPo
The bounty 将在 6 天后到期。这个问题的答案有资格获得 +50 声望奖励。 satan 29 想引起更多人对这个问题的关注: a modification that fits all th
这些功能是如何工作的?我正在使用 Python3.7 和 OpenCv 4.2.0。提前致谢。 approx = cv2.approxPolyDP(cnt, 0.01*cv2.arcLength(cn
我正在尝试将等高线转换为多边形曲线集,但是当我尝试使用 approxPolyDP 函数时卡住了。首先,我测试了 findContours 是否正常工作并尝试在我的图像中绘制轮廓 - 它适用于 cont
我想可视化用 cv2.approxPolyDP() 提取的多边形曲线。这是我正在使用的图像: 我的代码尝试隔离主岛并定义和绘制等高线近似值和等高线外壳。我绘制了绿色的轮廓,红色的近似值: import
我已成功将方法 cv::approxPolyDP 应用于轮廓 (cv::findContours),以便用更简单的多边形表示轮廓并隐式进行一些去噪。 我想在从 RGBD 相机(通常非常嘈杂)获取的边缘
我的 C++ 代码如下: // ROI by creating mask for the trapezoid Mat mask = Mat(frame.rows, frame.cols, CV_8UC
我无法使用 cv2.approxPolyDP() 绘制形状的完整轮廓。 我得到以下结果: 但我想要这样的输出: 这是我的代码: import cv2 im = cv2.imread('C:\Pytho
这个问题说明了一切 我有一些轮廓,我想从中得到最好的四边形 最佳答案 我遇到了圆角卡片的问题,即使我让 approxPolyDP() 只返回 4 个点/边,它也不是最好的,因为“角”经常被选得更近到这
我是一名优秀的程序员,十分优秀!