绘制从二值图像中检索到的轮廓
Drawing contours retrieved from the binary image
我想使用findContours
与二进制图像,但回调函数导致错误:
当返回RtlFreeHeap指定的地址无效
。
当我想使用clear()
来释放vector<vector<Point> >
值时,它会导致相同的异常,代码在free.c中崩溃:
if (retval == 0) errno = _get_errno_from_oserr(GetLastError());
例如:void onChangeContourMode(int, void *)
{
Mat m_frB = imread("3.jpg", 0);
vector<vector<Point>> contours
vector<Vec4i> hierarchy;
findContours(m_frB, contours, hierarchy, g_contour_mode, CV_CHAIN_APPROX_SIMPLE);
for( int idx = 0 ; idx >= 0; idx = hierarchy[idx][0] )
drawContours( m_frB, contours, idx, Scalar(255,255,255),
CV_FILLED, 8, hierarchy );
imshow( "Contours", m_frB );
}
有人能帮我吗?非常感谢!
Mat m_frB = imread("3.jpg", CV_LOAD_IMAGE_GRAYSCALE);
将3.jpg
加载为8bpp灰度图像,因此它不是二值图像。特定于findContours
函数,"非零像素被视为1。零像素仍然是0,因此图像被视为二进制""。还要注意,这个"函数在提取轮廓时修改图像"。
这里的实际问题是,虽然目标图像是8bpp,你应该确保它有3个通道使用CV_8UC3
之前,你绘制RGB轮廓到它。试试这个:
// find contours:
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
findContours(m_frB, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE);
// draw contours:
Mat imgWithContours = Mat::zeros(m_frB.rows, m_frB.cols, CV_8UC3);
RNG rng(12345);
for (int i = 0; i < contours.size(); i++)
{
Scalar color = Scalar(rng.uniform(50, 255), rng.uniform(50,255), rng.uniform(50,255));
drawContours(imgWithContours, contours, i, color, 1, 8, hierarchy, 0);
}
imshow("Contours", imgWithContours);
相关文章:
- 使用VerQueryValue检索应用程序的文件描述
- 是否可以从格式字符串中检索"width"
- 使用 pqxx 将 std::vector 存储在 postgresql 中,并从数据库中检索它
- 如何在QByteArray中放置和检索位字段而不会感到痛苦?
- 如何在Qt中从数据库中检索二进制数据?
- 如何从C++代码中检索 QML 的文本字段中的文本?
- 从 opencv c++ 中的矢量中检索固定的帧数
- 如何在不等待检索的情况下获取C++中的内存位置?
- 如何在 QTreeWidget 中检索特定项目的 mimeData?
- C++从字符串中检索几行
- 在数据库中插入和检索矩阵
- 两个垫子的 OpenCV 数据是相同的,但使用 Mat::at 检索时的值已损坏
- 使用 const char* 键映射 C++ 检索空值
- 打印从SQLite3数据库检索的数据C++与命令行中相同的方式
- 如何检索指向在单独线程上运行的函数的移动指针?
- 如何检索 Steamwork SDK 的当前版本
- 通过 host() 从 af::array 检索数据会导致错误的数据
- 绘制从二值图像中检索到的轮廓
- 如何检索轮廓点-转换为矢量使用opencv
- 在opencvc++中使用fillpoly检索轮廓