Ask Your Question
0

initialise a 4 channel matrix opencv

asked 2018-05-07 03:32:50 -0600

infoclogged gravatar image

I am trying to initialise a 4 channel matrix with row = 1 and columns = 5, but I am always getting an exception error: (-215) (unsigned)(i1 * DataType<_Tp>::channels) < (unsigned)(size.p[1] * channels()) . Anyone knows what I am doing wrong.

            cv::Mat_<char> samples(1,5,CV_8UC4);

            samples.at<cv::Vec4b>(0,0) =  { 1,  2 , 3 , 4 } ;
            samples.at<cv::Vec4b>(0,1) =  { 1,  2 , 3 , 4 } ;
            samples.at<cv::Vec4b>(0,2) =  { 1,  2 , 3 , 4 } ;
            samples.at<cv::Vec4b>(0,3) =  { 1,  2 , 3 , 4 } ;
            samples.at<cv::Vec4b>(0,4) =  { 1,  2 , 3 , 4 } ;
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2018-05-07 03:41:39 -0600

LBerger gravatar image

Mat_<char> and CV_8UC4 it is strange. try like this :

cv::Mat samples(1, 5, CV_8UC4);

samples.at<cv::Vec4b>(0, 0) = { 1,  2 , 3 , 4 };
samples.at<cv::Vec4b>(0, 1) = Vec4b(1, 2, 3, 4);
samples.at<cv::Vec4b>(0, 2) = Vec4b(1, 2, 3, 4);
samples.at<cv::Vec4b>(0, 3) = Vec4b(1, 2, 3, 4);
samples.at<cv::Vec4b>(0, 4) = { 1,  2 , 3 , 4 };
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-05-07 03:32:50 -0600

Seen: 183 times

Last updated: May 07 '18