cvStartFindContours 出现奇怪的问题?
每当我将图像传递给 cvStartFindContours 时,我的图像就会变成全黑,而不是找到轮廓。我完全不知道为什么。我知道这不是由代码的另一部分引起的,即使我注释掉所有内容,但保留对 cvStartFindContours 的函数调用,我的图像仍然变黑。然而,当我注释掉对 cvStartFindContours 的调用时,我的图像仍然正常。为什么会发生这种情况?我传入的图像 (skinMask) 是一个包含数据的 8 位、1 通道图像 (IPL_DEPTH_8U)。 (它不是黑色的,上面有白色的碎片)。
为什么我的图像变黑了?谢谢
void connectedComponents ()
{
cvMorphologyEx (skinMask, skinMask, 0, 0, CV_MOP_OPEN, 1);
cvMorphologyEx (skinMask, skinMask, 0, 0, CV_MOP_CLOSE, 1);
CvMemStorage *connectedCompStorage = cvCreateMemStorage (0);
CvSeq *temp = NULL; //used to loop through contour perimeter checking
CvSeq *connectedComp = NULL; //stores all derived connected component contours
CvContourScanner connectedCompScanner = cvStartFindContours (skinMask, connectedCompStorage); //FUNCTION CALL CAUSING PROBLEMS
while ((temp = cvFindNextContour (connectedCompScanner)) != NULL)
{
double perimeter = cvContourPerimeter (temp);
if (perimeter < CC_PERIMETER_THRESH)
{
cvSubstituteContour (connectedCompScanner, NULL);
}
else
{
temp = cvApproxPoly (temp, sizeof (CvContour), connectedCompStorage, CV_POLY_APPROX_DP, 2, 0);
cvSubstituteContour (connectedCompScanner, temp);
}
}
connectedComp = cvEndFindContours (&connectedCompScanner);
cvZero (skinMask);
for (temp = connectedComp; temp != NULL; temp = temp -> h_next);
{
cvDrawContours (skinMask, temp, cvScalar (255, 255, 255), cvScalar (0, 0, 0), -1, CV_FILLED, 8);
}
cvReleaseMemStorage (&connectedCompStorage);
}
Whenever I pass in an image to cvStartFindContours, instead of finding the contours, my image turns completely black. I have absolutely no idea why. I know this isn't caused by another part of the code even if I comment everything out, but leave in the function call to cvStartFindContours, my image still turns black. However the second I comment out the call to cvStartFindContours, my image remains normal. Why is this happening? The image I pass in (skinMask) is a 8 bit, 1 channel image (IPL_DEPTH_8U) with CONTAINS data. (it isn't black it has pieces of white on it).
Why is my image turning black? Thanks
void connectedComponents ()
{
cvMorphologyEx (skinMask, skinMask, 0, 0, CV_MOP_OPEN, 1);
cvMorphologyEx (skinMask, skinMask, 0, 0, CV_MOP_CLOSE, 1);
CvMemStorage *connectedCompStorage = cvCreateMemStorage (0);
CvSeq *temp = NULL; //used to loop through contour perimeter checking
CvSeq *connectedComp = NULL; //stores all derived connected component contours
CvContourScanner connectedCompScanner = cvStartFindContours (skinMask, connectedCompStorage); //FUNCTION CALL CAUSING PROBLEMS
while ((temp = cvFindNextContour (connectedCompScanner)) != NULL)
{
double perimeter = cvContourPerimeter (temp);
if (perimeter < CC_PERIMETER_THRESH)
{
cvSubstituteContour (connectedCompScanner, NULL);
}
else
{
temp = cvApproxPoly (temp, sizeof (CvContour), connectedCompStorage, CV_POLY_APPROX_DP, 2, 0);
cvSubstituteContour (connectedCompScanner, temp);
}
}
connectedComp = cvEndFindContours (&connectedCompScanner);
cvZero (skinMask);
for (temp = connectedComp; temp != NULL; temp = temp -> h_next);
{
cvDrawContours (skinMask, temp, cvScalar (255, 255, 255), cvScalar (0, 0, 0), -1, CV_FILLED, 8);
}
cvReleaseMemStorage (&connectedCompStorage);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我也被这个咬过。来自
findContours
的 OpenCV 文档:因此,如果您不希望修改
skinMask
图像,则需要传入它的副本...I have been bitten by this as well. From the OpenCV documentation for
findContours
:So, if you don't want your
skinMask
image to be modified, you need to pass in a copy of it...