Ask Your Question
0

How to convert or format from std::vector to cv::Mat3b?

asked 2017-06-29 13:43:51 -0600

I have a vector of color rgb image data that I'm trying to encode to jpeg format but I can not do this until I can move the data to a Mat3b object. Does anyone have simple method to resolve this? The image is 480*640.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-06-29 14:09:17 -0600

LBerger gravatar image

Using a vector of vec3b you can try :

    vector<Vec3b> v={Vec3b(0,1,2),Vec3b(3,4,5),Vec3b(6,7,8),Vec3b(10,11,12)};
    Mat x(v);
    cout<< x<<"\n";
    cout<<"row,col,channel = "<<x.rows<<" "<<x.cols<<" "<<x.channels()<<"\n";
    x = x.reshape(3,2);
    cout << x << "\n";
    cout << "row,col,channel = " << x.rows << " " << x.cols << " " << x.channels() << "\n";

and results are

[  0,   1,   2;
   3,   4,   5;
   6,   7,   8;
  10,  11,  12]
row,col,channel = 4 1 3
[  0,   1,   2,   3,   4,   5;
   6,   7,   8,  10,  11,  12]
row,col,channel = 2 2 3
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-06-29 13:43:51 -0600

Seen: 235 times

Last updated: Jun 29 '17