Ask Your Question
0

video watermarking

asked 2014-07-12 07:22:22 -0600

Mahavir gravatar image

updated 2014-07-12 07:23:30 -0600

I am doing video watermarking in dct using C++ ..code is as shown below I havefollowing problem I cant see watermark in watermarked video. What should i do so watermark becomes visible..I change scales of DCT coe. of watermark but i did not get the desired result..

    #include"opencv2\highgui\highgui.hpp"
    #include "opencv2\core\core.hpp" 
    #include<opencv2\imgproc\imgproc.hpp>
    #include<iostream>
    #include<math.h>
    using namespace std;
    using namespace cv;
    void wat();
    void ext();
    Mat img,img1;
    int main()
    {
       wat();
       Mat f1,f2,f3,f4;
       VideoCapture cap("C:\\Users\\MAHAVIR\\Desktop\\1.3gp");

       if(!cap.isOpened())
       {
           cout<<"File is Missing"<<endl;   //File is not opened
           return -1;
       }

       double fps=cap.get(CV_CAP_PROP_FPS);
       double cnt=cap.get(7);
       VideoWriter v ("C:/Users/MAHAVIR/Desktop/out.avi",-1,fps,Size(256,256),true); //initialize the VideoWriter object
        if ( !v.isOpened() ) //if not initialize the VideoWriter successfully, exit the program
       {
           cout << "ERROR: Failed to write the video" << endl;
           return -1;
       }


          cout<<"Frame rate is"<<fps<<endl;
          cout<<"Frame Count is"<<cnt<<endl;
          namedWindow("Input Video",CV_WINDOW_AUTOSIZE);

      for(int i=0;i<cnt;i++)
      {
          Mat frame;

          bool f=cap.read(frame);
           if (!f) //if not success, break loop
         {
           cout << "Cannot read the frame from video file" << endl;
           break;
         }
           cvtColor(frame,f1,CV_RGB2GRAY);
           resize(f1,f2,Size(256,256));
           imshow("Input Video",f2);
           f2.convertTo(f2,CV_32F);
           dct(f2,f2,0);
           f2.copyTo(f3);

           for(int m=0;m<2;m++)
           {
               for(int n=0;n<2;n++)
               {
                   float p,q,r;
                   p=f2.at<float>(m,n);
                    //cout<<"Val"<<p<<endl;
                   q=img1.at<float>(m,n);
                   //cout<<"\tVal"<<q<<endl;
                   r=p+q;
                   //cout<<"\t\tVal"<<r<<endl;
                   f3.at<float>(m,n)=r;
               }
           }

            idct(f3,f3);
            f3.convertTo(f3,CV_8U); 
            v.write(f3);
            imshow("Watermarked Video",f3);
            waitKey(10);
      }
      waitKey(10);
      ext();
      cvDestroyWindow("Input Video");
      cvDestroyWindow("WaterMarked Video");
      return 0;  
    }

    void wat()
    {
        img=imread("C:\\Users\\MAHAVIR\\Documents\\MATLAB\\host image.jpg",CV_LOAD_IMAGE_UNCHANGED);
        cvtColor(img,img,CV_RGB2GRAY);
        if (img.empty()) //check whether the image is loaded or not
        {
            cout << "Error : Image cannot be loaded..!!" << endl;
              //system("pause"); //wait for a key press
        }
        else
        {
         //img.resize(img1,(64,64));
         namedWindow("Watermark", CV_WINDOW_AUTOSIZE); //create a window with the name "MyWindow"
         imshow("Watermark", img); //display the image which is stored in the 'img' in the "MyWindow" window
         img.convertTo(img,CV_32F,(1.0),(0.0));
         dct(img,img,0);
         img.copyTo(img1);
        }
    }
edit retag flag offensive close merge delete

Comments

+1 for the heroic rewrite.

i think, your scale-factors for convertTo are all off.

to get from uchar[0..255] to float[0..1] space you need a.convertTo(b,CV_32F,1.0/255);

to get from float[0..1] back to uchar[0..255] space you need a.convertTo(b,CV_8U,255);

also note that dct() may return values>1

berak gravatar imageberak ( 2014-07-12 08:02:42 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2014-07-13 22:59:17 -0600

Mahavir gravatar image

@beark thank you sir..Now i can see my inserted watermark....

edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-07-12 07:22:22 -0600

Seen: 2,130 times

Last updated: Jul 12 '14