Ask Your Question

Guru978's profile - activity

2018-07-17 19:29:49 -0600 received badge  Notable Question (source)
2018-07-17 19:29:49 -0600 received badge  Popular Question (source)
2014-03-14 21:32:27 -0600 received badge  Editor (source)
2014-03-14 21:31:34 -0600 asked a question Subtraction manually

Hi Folks, I'm trying to implement a function which is subtracting 2 images. (the same does subtract() of opencv)...but since OpenCv often needs 8bit-single Channel images I have to normalize my images before subtracting because the images are CV_16UC1. As I want to save time I want to have the images subtracted before normalizing.

so i did it this way: (back-front=mask)

Mat moving=Mat::zeros(240,320,CV_8UC1);
for(int i=0;i<240;i++){
    unsigned short* rowF=front.ptr<unsigned short>(i);
    unsigned short* rowB=back.ptr<unsigned short>(i);
    uchar* rowM=mask.ptr<uchar>(i);
    uchar fg=255;
    uchar bg=0;
for(int j=0;j<320;j++){
   unsigned short m=rowB[j]-rowF[j];
   if(m>=300){ rowM[j]=fg;
      }else rowM[j]=bg;

  }
}

it runs, but: not with the same result. When I try:

cout<<"120,160"<<":"<<back.at<unsigned short>(120,160)<<endl;

the value of back is displayed. but when I move in front of the camera, the back-value changes to the front value. And the back-image is a still image which is never changed after initialization.

I don't have any ideas what I've done wrong, but you?. Thx for Your help!

2013-12-18 16:35:50 -0600 asked a question Problem reading values from normalized Mat

Hello everyone,

I have to come up again with a question.

My Problem: I subtract 2 Mat (each CV_16UC1 normalized to CV8_UC1) with the following code:

normalize(src1,dst1,0,255,NORM_MINMAX,CV_8UC1);
normalize(src2,dst2,0,255,NORM_MINMAX,CV_8UC1);
subtract(dst1,dst2,finaldestination);

now i want to access the values with:

finaldestination.at<uchar>(x,y)...

but every datatype I try brings a letter, a funny box but not the value...(the picture output with imshow is correct...) (I tried uchar, unsigned character, unsigned short, ushort...nothing works)

Any suggestions for me? Thx in advance!