【发布时间】:2020-05-02 10:24:36
【问题描述】:
我需要使用具有签名的函数 split() :
void split(const Mat& src, Mat* mvbegin)
我通过official documentation 发现了这个签名。 我尝试了以下方法:
#include<opencv2/opencv.hpp>
#include<stdint.h>
#include<array>
#include<vector>
using namespace std;
using namespace cv;
int main(){
//Common Parts :
//Loading the image :
Mat modified1 = imread("sample.jpg",CV_LOAD_IMAGE_COLOR);
/* ATTEMPT 1 : This works :
*********************/
vector<cv::Mat> rgb ;
cv::split(modified1 , rgb);
/********************/
/* ATTEMPT 2 : Does not work
********************/
Mat* rgb1{nullptr} ;
//rgb1 = &modified1; Doesn't make a difference.
cv::split(modified1 , rgb1);
/********************/
return 0 ;
}
Attempt 1 有效,这就是我看到人们在 stackoverflow 上搜索答案时所做的事情。
我为Attempt2 得到的错误是:segmentation fault (core dumped)
我的问题是:
1.)当我遵循函数签名时,为什么Attempt2 不起作用?
2.)为什么Attempt1 有效?
【问题讨论】:
-
您应该提供一个准备好的空 Mat 对象数组。
split()不会为你分配数组。 -
谢谢,文档中没有明确写出来。
标签: c++ opencv c++14 opencv3.0