Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/161.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 二进制cv::mat的侵蚀错误_C++_Opencv - Fatal编程技术网

C++ 二进制cv::mat的侵蚀错误

C++ 二进制cv::mat的侵蚀错误,c++,opencv,C++,Opencv,所以我试图腐蚀一个二进制矩阵。 我使用以下代码创建矩阵: cv::Mat tmp = cv::Mat::zeros( IMG->width, IMG->height, CV_8U ); for( auto i = 0 ; i < IMG->width ; i++) { for ( auto j = 0 ; j < IMG->height ; j++) { if( cv::pointPolygonTest(cv::Mat(co

所以我试图腐蚀一个二进制矩阵。 我使用以下代码创建矩阵:

cv::Mat tmp = cv::Mat::zeros( IMG->width, IMG->height, CV_8U );

for( auto i = 0 ; i < IMG->width ; i++)
{
    for ( auto j = 0 ; j < IMG->height ; j++)
    {
        if(  cv::pointPolygonTest(cv::Mat(contour),cv::Point(i,j),true) < 0 )
        {
            tmp.at<double>(i,j) = 255;
        }
    }

}   
int erosion_elem = 1;
int erosion_size = 8;


int erosion_type;
if( erosion_elem == 0 ){ erosion_type = MORPH_RECT; }
else if( erosion_elem == 1 ){ erosion_type = MORPH_CROSS; }
else if( erosion_elem == 2) { erosion_type = MORPH_ELLIPSE; }

Mat element = getStructuringElement( erosion_type,
                                   Size( 2*erosion_size + 1, 2*erosion_size+1 ),
                                   Point( erosion_size, erosion_size ) );

/// Apply the erosion operation
erode( binary, erosion_dst, element );`
所以它编译得很好,但我在这一行遇到了一个例外:

erode( binary, erosion_dst, element );`
它说它是一种不受支持的数据类型。 有人知道我为什么会遇到这个异常吗

我试图更改矩阵tmp的数据类型,但我有相同的错误


谢谢你的帮助

二进制图像像素存储为
无符号字符
(CV_8U->on 8bits->1字节), 您也应该将像素值存储为
无符号字符

cv::Mat tmp = cv::Mat::zeros( IMG->width, IMG->height, CV_8U );

for( auto i = 0 ; i < IMG->width ; i++)
{
    for ( auto j = 0 ; j < IMG->height ; j++)
    {
        if(  cv::pointPolygonTest(cv::Mat(contour),cv::Point(i,j),true) < 0 )
        {
            tmp.at<unsigned char>(i,j) = 255;
        }
    }

}
cv::Mat tmp=cv::Mat::zeros(IMG->width,IMG->height,cv_8U);
用于(自动i=0;iwidth;i++)
{
用于(自动j=0;jheight;j++)
{
如果(cv::PointPolyContest(cv::Mat(等高线),cv::Point(i,j),true)<0)
{
tmp.at(i,j)=255;
}
}
}

(从评论中获得答案)

您的二进制图像是用CV_8U(无符号字符)存储的,您可以尝试
tmp.at(i,j)=255填充你的tmp垫?@Marcassin是的,很有效,谢谢!我昨天更改了矩阵的数据类型,只是在填写时忘了更改它。我觉得自己好笨!再次感谢你@Sherokan接受下面的答案以结束问题。