Video Watermarking

asked 2014-07-05 00:27:48 -0500

Mahavir gravatar image

Hello, I am doing video watermarking using Opencv 2.4.9 and writing code using c interface. At this time I am able to add watermark in video and save that video to other location. I have two problems 1. I am unable to store it in color form. It is stored in gray-level form only. 2. When I capture that video again for watermark extraction code does not work.. I am giving code below What are mistakes in code..I am unable to figure it out..I can play the stored video externally using VLC player..

// Code for Video Watermarking in DCT Doamin

include<math.h>

include<stdio.h>

include<opencv\cv.h>

include<opencv\highgui.h>

using namespace cv; void wat(); void ext(); IplImage *frame=0; CvCapture *capture=0; CvCapture *capture1=0; CvVideoWriter *writer=0; IplImage *wm4=0; // DCT of Watermark IplImage *dst=0;
IplImage *dst1=0; IplImage *gray2=0; int cnt,fps,i,h,w,m,n; void main() {
cvNamedWindow( "Input Video",CV_WINDOW_AUTOSIZE); //Name of window is input window and it is Noramal Sized CvCapture *capture=cvCreateFileCapture("C:\Users\MAHAVIR\Desktop\1_1.mp4"); //Give path of video file fps=cvGetCaptureProperty (capture,5); //Show the frame Rate cnt=cvGetCaptureProperty (capture,7); //Show frame Count h=cvGetCaptureProperty (capture,3); //Show frame Height w=cvGetCaptureProperty (capture,4); //Show Frame Width wat(); writer=cvCreateVideoWriter("out.avi",-1,fps,cvSize(256,256),1); //Output video for (i=0;i<cnt;i++) {="" input="" frame<="" p="">

    frame=cvQueryFrame(capture);  
    IplImage* gray1 = cvCreateImage(cvSize(256,256),8,3); 
    cvResize(frame,gray1,1);  
    gray2 = cvCreateImage(cvSize(256,256),8,1); 
    cvCvtColor(gray1, gray2, CV_BGR2GRAY);   
     cvShowImage( "Input Video",gray2);          
    //DCT

    IplImage *src = cvCreateImage(cvGetSize(gray2),32,1);
    cvConvert(gray2,src);
    IplImage *dst = cvCreateImage(cvGetSize(gray2),32,1);
    IplImage *dsti = cvCreateImage(cvGetSize(gray2),32,1);
    cvDCT(src,dst,CV_DXT_FORWARD);
    cvCopy(dst,dsti,0);                     //Copy contenr of dst to dsti
    // Logic for Insertion of Watermark

    for(m=0;m<64;m++)
    {
        for(n=0;n<64;n++)
        {
            CvScalar s,w1,s1;
            s=cvGet2D(dst,m,n); // get the (i,j) pixel value of frame
            w1=cvGet2D(wm4,m,n);
            s1.val[0]=s.val[0]+w1.val[0];
            cvSet2D(dsti,m,n,s1);
        }
    }

    //IDCT to get watermark image

    IplImage *dst1 = cvCreateImage(cvGetSize(gray2),32,1);
    cvDCT(dsti,dst1,CV_DXT_INVERSE);
    IplImage *dst2 = cvCreateImage(cvGetSize(gray2),8,1);
    cvConvert(dst1,dst2);
    cvNamedWindow("Watermarked Video",CV_WINDOW_AUTOSIZE);
    cvShowImage("Watermarked Video",dst2);
    cvWriteFrame(writer,dst2);
    cvWaitKey(10);  
    cvReleaseImage(&gray1);
    cvReleaseImage(&dst2);


  }

cvReleaseCapture( &capture ); cvReleaseVideoWriter(&writer);

cvDestroyWindow("Input Video" ); cvDestroyWindow("Watermarked Video"); ext(); } void wat() { // DCT of Watermark

    cvNamedWindow("Watermark",CV_WINDOW_AUTOSIZE);
    IplImage*wm=cvLoadImage("C:\\Users\\MAHAVIR\\Documents\\MATLAB\\lena.jpg");
    IplImage*wm1=cvCreateImage(cvSize(64,64),8,3);
    cvResize(wm,wm1,1);
    IplImage*wm2=cvCreateImage(cvSize(64,64),8,1);
    cvCvtColor(wm1,wm2,CV_RGB2GRAY);
    cvShowImage("Watermark",wm2);
    IplImage *wm3 = cvCreateImage(cvGetSize(wm1),32,1);
    cvConvert(wm2,wm3);
    wm4 = cvCreateImage(cvGetSize(wm1),32,1);
    cvDCT(wm3,wm4,CV_DXT_FORWARD);
    cvConvertScale(wm4,wm4,1/255);

}

void ext() { CvCapture capture1=cvCreateFileCapture("out.avi"); cvNamedWindow("Saved Video",1); int ... (more)

edit retag flag offensive close merge delete