繁体   English   中英

用数据初始化cv :: Mat不起作用

[英]Initializing cv::Mat with data doesn't work

此示例之后,我尝试使用以下值初始化openCV Mat

cv::Mat image = (cv::Mat_<int>(3,3) << 0, 255, 0, 0, 255, 0, 0, 255, 0);

但是,我的IDE抱怨

Binary operator '<<' can't be applied to the expressions of type 'cv::Mat_<int>' and 'int'

而当我得到

OpenCV Error: The function/feature is not implemented (Unsupported combination of source format (=4), and buffer format (=5)) in getLinearRowFilter, file /build/buildd/opencv-2.4.8+dfsg1/modules/imgproc/src/filter.cpp, line 2857
terminate called after throwing an instance of 'cv::Exception'
  what():  /build/buildd/opencv-2.4.8+dfsg1/modules/imgproc/src/filter.cpp:2857: error: (-213) Unsupported combination of source format (=4), and buffer format (=5) in function getLinearRowFilter

我在Python上使用openCV已经有一段时间了,但是我完全迷失了在C ++中使用它的感觉。

您可能正在尝试应用使用getLinearRowFilter()的函数(或过滤器)(例如Sobel等),并且正在使用不允许的类型组合(输入和输出)。

您可以在此处检查允许的组合,其中sdepth是源的深度( input ), ddepth是目标的深度( output ):

// these are allowed, otherwise the error will be thrown
if( sdepth == CV_8U && ddepth == CV_32S )
if( sdepth == CV_8U && ddepth == CV_32F )
if( sdepth == CV_8U && ddepth == CV_64F )
if( sdepth == CV_16U && ddepth == CV_32F )
if( sdepth == CV_16U && ddepth == CV_64F )
if( sdepth == CV_16S && ddepth == CV_32F )
if( sdepth == CV_16S && ddepth == CV_64F )
if( sdepth == CV_32F && ddepth == CV_32F )
if( sdepth == CV_32F && ddepth == CV_64F )
if( sdepth == CV_64F && ddepth == CV_64F )

基于该错误,您可能正在使用CV_32S= 4 )输入和CV_32F= 5 )输出。 基本上,您不能在使用getLinearRowFilter()函数CV_32SMat_<int> )用作输入。

要解决此问题,您可以在使用输入之前先对其进行转换。 例如:

cv::Mat1i image = ...; // suppose this is your input (CV_32S == Mat_<int>)
cv::Mat1f output = ...; // suppose this is your output (CV_32F == Mat_<float>)

image.convertTo(image, CV_32F); // add this line right before the call
call_to_filter(image, output, ...); // your function (or filter) call
// e.g.: cv::Sobel(image, output, ...) will throw this error without convertion

注意:由于并非所有相关代码都在问题中,因此信息不准确。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM