Ask Your Question
0

The problem of the mask?

asked 2018-03-11 08:08:24 -0600

Weifa Gan gravatar image

updated 2018-03-11 08:45:13 -0600

LBerger gravatar image

I don't know how to use the mask. Some problem has occur when i use the following codes,but i don't know why. please help me to understand.thank you!

#include<iostream>
#include<opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>

using namespace std;
using namespace cv;
int main()
{
    Mat_<float> m(3, 3);
    m << 1.0f, 2.0f, 3.9f, 4.0f, 5.0f, 6.0f, 7.7f, 8.0f, 9.0f;

    Mat_<int> mask1(3, 3);
    mask1 << 1, 2, 3, 0,1,2,3,0,0;

    Mat m2;
    m.copyTo(m2,mask1);

    cout<< m2 << endl;

       system("pause");
}
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-03-11 08:53:13 -0600

LBerger gravatar image

updated 2018-03-12 11:59:00 -0600

" Some problem has occur" must we guess it?

a mask is binary 0 or non zero and it should be uchar

Mat mask = (Mat_<uchar>(3, 3) << 1, 1, 1, 0, 1, 1, 1, 0, 0);
Mat_<float> m(3, 3);
m << 1.0f, 2.0f, 3.9f, 4.0f, 5.0f, 6.0f, 7.7f, 8.0f, 9.0f;
Mat m2;
m.copyTo(m2, mask);

becarefull some values of m2 are not initiliased

I think books are always necessary : Learning OpenCV: Computer Vision with the OpenCV Library Par Gary Bradski,Adrian Kaehler

image description

edit flag offensive delete link more

Comments

Yeah,Thanks a lot.And how do you know that?

Weifa Gan gravatar imageWeifa Gan ( 2018-03-12 07:02:17 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-03-11 08:08:24 -0600

Seen: 204 times

Last updated: Mar 12 '18