Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/151.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++ 如何使用GCC编译器创建新的OpenCV Mat对象?_C++_Opencv_Gcc - Fatal编程技术网

C++ 如何使用GCC编译器创建新的OpenCV Mat对象?

C++ 如何使用GCC编译器创建新的OpenCV Mat对象?,c++,opencv,gcc,C++,Opencv,Gcc,我有灰色的垫子(图)。我想创建与灰色图像大小相同的彩色图像: 用VisualC++显示,编译: Mat dst = cvCreateImage(gray.size(), 8, 3); 但GCC编译器的错误是: threshold.cpp|462|error: conversion from ‘IplImage* {aka _IplImage*}’ to non-scalar type ‘cv::Mat’ requested| 我换成cvCreateMat Mat dst = cvCreate

我有灰色的垫子(图)。我想创建与灰色图像大小相同的彩色图像: 用VisualC++显示,编译:

Mat dst = cvCreateImage(gray.size(), 8, 3);
但GCC编译器的错误是:

threshold.cpp|462|error: conversion from ‘IplImage* {aka _IplImage*}’ to non-scalar type ‘cv::Mat’ requested|
我换成cvCreateMat

Mat dst = cvCreateMat(gray.rows, gray.cols, CV_8UC3);
但GCC仍然:

threshold.cpp|462|error: conversion from ‘CvMat*’ to non-scalar type ‘cv::Mat’ requested|
方法是直接创建还是进行任何转换

cvCreateImage(gray.size(), 8, 3);
来自旧的、不推荐使用的c-api。不要使用它(它实际上是在创建IplImage*)

构建一个cv::Mat,如下所示:

Mat dst(gray.size(), CV_8UC3); // 3 uchar channels
请注意,您永远不必为结果图像预先分配任何内容

因此,如果你想做一个阈值操作,它只是:

Mat gray = ....;
Mat thresh; // intentionally left empty!
threshold( gray,thresh, 128,255,0);
// .. go on working with thresh. no need to release it either.
来自旧的、不推荐使用的c-api。不要使用它(它实际上是在创建IplImage*)

构建一个cv::Mat,如下所示:

Mat dst(gray.size(), CV_8UC3); // 3 uchar channels
请注意,您永远不必为结果图像预先分配任何内容

因此,如果你想做一个阈值操作,它只是:

Mat gray = ....;
Mat thresh; // intentionally left empty!
threshold( gray,thresh, 128,255,0);
// .. go on working with thresh. no need to release it either.