OpenCV使用Mat来修改视频像素值并合并回来

时间:2014-05-25 09:20:18

标签: mat

你真的希望有人可以帮我解决这个问题,已经停留了很长一段时间。在x = 100处改变蓝色的像素值之后,y = 200并且合并为fin_vid。

当我从fin_vid读回来时,该值似乎与我想要的值相同。

我的合并有问题,但我不明白为什么。

 split(frame, rgb);

 Mat fin_vid, tmp;

 namedWindow("blue",1);

 imshow("Original Video", frame); 

 imshow("blue", rgb[0]);


       if (waitKey(30) == 27) //wait for 'esc' key press for 30 ms. If 'esc' key is    pressed, break loop
       {
               cout << "esc key is pressed by user" << endl; 
               break; 
       }
       rgb[0].convertTo(tmp, CV_8UC1);
    for(int j = 0; j<ModText.size(); j++)
    {

        for(int k = 0; k<8; k++)
        {

            int blue = (int)tmp.at<uchar>(hx+j,wy+k);


                cout<<blue<<endl;          
           if (blue%2==1)
           {
            if ( ary[j][k]== 48){                   
                blue = blue - 1;
            }
           }            
            else if( ary[j][k] == 49) {
                    blue =  blue + 1;
            }

tmp.at<uchar>(hx+j,wy+k)=blue;

cout << "the new value of the pixel is " << (int)(tmp.at<uchar>(hx+j,wy+k)) << endl;}               

vector<Mat> channels;

channels.push_back(tmp);

channels.push_back(rgb[1]);

channels.push_back(rgb[2]);

merge(channels, fin_vid);

namedWindow("B",1);imshow("B", fin_vid);

namedWindow("watermarked video");

imshow("watermarked video", fin_vid);

outputVideo.write(fin_vid);


}

0 个答案:

没有答案