Ask Your Question

VideoWM's profile - activity

2020-05-06 03:26:56 -0600 received badge  Famous Question (source)
2018-07-01 03:05:15 -0600 received badge  Notable Question (source)
2018-05-11 04:01:48 -0600 received badge  Popular Question (source)
2015-03-23 04:24:45 -0600 received badge  Student (source)
2014-07-28 06:16:10 -0600 asked a question How to skip the first 2 frames?

Hi I have a while(1) which does a infinite loop, is there a way to ignore the first 2 frames?

while(1)
{
    bool bSuccess = capture.read(fullimage); // read a new frame from video

    if (!bSuccess)                          //if not success, break loop
    {
        cout << "End of video" << endl;
        destroyWindow("Original Video");
        destroyWindow("dctBlockImage");
        break;
    }

    imshow("Original Video", fullimage);    //show the frame in "Original Video" window

    FrameTo8by8(myinput,3.0);               //Proccess and algorithm

    oVideoWriter.write(dctImage);           //write video to file

    namedWindow("dctBlockImage"); 
    imshow("dctBlockImage", dctImage);      //display watermarked image


    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; 
    }
}

Is there a way to skip the first 2 frames?

2014-07-27 10:03:57 -0600 commented question I have edited the pixel value, how do i save it?

@unxnut i try changing to idct(planes[0], outplanes[0]); but still the same result.

2014-07-27 08:05:42 -0600 commented question I have edited the pixel value, how do i save it?

@unxnut hi thanks for the comment how do i determine if input and output arrays for the operations are different? any example?

2014-07-27 07:20:41 -0600 asked a question I have edited the pixel value, how do i save it?

I am able to edit and set the pixel value i want but i can't seems to save it.

When i cout before idct the value is corect but after idct the value is set to 0.

for (int i = 0; i < height-16; i += 16) 
{ 
    for (int j = 0; j < width-16; j+= 16) 
    {

            Mat block = dctImage(Rect(j, i, 8, 8)); //Draw rectangle box of 8x8
            vector<Mat> planes; 
            split(block, planes);                   //Split image

            vector<Mat> outplanes(planes.size());

            for (size_t k = 0; k < planes.size(); k++)
            {
                outplanes[k]=planes[k];
            }

            planes[0].convertTo(planes[0], CV_32FC1);   //Convert to float value
            dct(planes[0], outplanes[0]);               //Do DCT

            for (int x=2; x<4; x++)
            {
                for (int y=2; y<4; y++)
                {
                    if (inputTmp==0)
                    {
                        outplanes[0].at<float>(x,y) = avg + 3;
                        cout << outplanes[0].at<float>(x,y) << endl;
                    }

                    else
                    {
                        outplanes[0].at<float>(x,y) = avg - 3;
                        cout << outplanes[0].at<float>(x,y) << endl;
                    }
                }
            }

            for ( int i=0; i<8; i++)
            {
                for ( int j=0; j<8; j++)
                {
                    cout << "the dct value at position (" << i << "," << j << ") is :" << outplanes[0].at<float>(i,j) << endl; 
                }
            }

            //Do inverse DCT (Disable this function will make 8x8 pix visible
            idct(outplanes[0], outplanes[0]);           


            //Debug purpose
            dct(planes[0], outplanes[0]);               //Do DCT

            //Show pixel value after modifying
            for ( int i=0; i<8; i++)
            {
                for ( int j=0; j<8; j++)
                {
                    cout << "the dct value at position (" << i << "," << j << ") is :" << outplanes[0].at<float>(i,j) << endl; 
                }
            }

            //Convert to 1 channel
            outplanes[0].convertTo(outplanes[0], CV_8UC1);

            //Merge image
            merge(outplanes, block); 

        } 
    }

Did i do anything wrongly. Please advise on this.

2014-07-13 01:43:37 -0600 asked a question OpenCV C++ How to embed binary numbers into pixel in video?

Currently my programme can read binary numbers (eg. if I type ABC into my programme, it will convert to binary) and for every frame in a 8 by 8 block, one pixel (3,3) in the mid-band freq will be embed with 1 binary bit.

This cpp convert user input into binary.

UserInfo.cpp

vector<int> UserInfo::UserInputList() const
{
string input;
vector<int> charList;
vector<int> binarylist;

cout << "Please enter message : " << endl;
cin >> input;

int binary [8];

for(int i = 0; i <input.length(); i++)
{
    int number = (int) input.at(i);
    int value = number;

    charList.push_back(number);
    cout << number << endl;


    for(int u = 0; u < 8; u++)
    {
        binary[7 - u] = value%2;

        value = value/2;

        binarylist.push_back(binary[7 - u]);

        cout << binary[7 - u] << endl;
    }
}
return binarylist;
}

This cpp split video into 8 by 8, split rgb channel, convert to dct and embed binary.

VideoSplitEngine.cpp

Mat VideoSplitEngine::Start(vector<int> myinput)
{

while(1)
{
    bool bSuccess = capture.read(fullimage); // read a new frame from video

    if (!bSuccess) //if not success, break loop
    {
        cout << "End of video" << endl;
        destroyWindow("Original Video");
        destroyWindow("dctBlockImage");
        break;
    }

    imshow("Original Video", fullimage); //show the frame in "Original Video" window

    FrameTo8by8(myinput);

    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; 
    }
}

return fullimage;
}


void VideoSplitEngine::FrameTo8by8(vector<int> myinput) const
{
    int width = fullimage.size().width; 
    int height = fullimage.size().height; 

    cout << "Original image Width x Height is " << width << "x" << height << endl; 

    // Leave original alone, work on a copy 
    Mat dctImage = fullimage.clone();

    // Step through the copied image with rectangles size 8x8 
    // For each block, split into planes, do dct, and merge back 
    // into the block. (This will affect the image from 
    // which the block is selected each time.) 

    for (int i = 0; i < height-16; i += 16) 
    { 
        for (int j = 0; j < width-16; j+= 16) 
        {
            Mat block = dctImage(Rect(j, i, 8, 8));
            vector<Mat> planes; 
            split(block, planes);

            vector<Mat> outplanes(planes.size());

            for (size_t k = 0; k < planes.size(); k++)
            {
                outplanes[k]=planes[k];
            }

            planes[0].convertTo(planes[0], CV_32FC1); 
            dct(planes[0], outplanes[0]);
            //embed your message here

            idct(outplanes[0], outplanes[0]);
            outplanes[0].convertTo(outplanes[0], CV_8UC1);

            merge(outplanes, block); 
        } 
    } 

    namedWindow("dctBlockImage"); 
    imshow("dctBlockImage", dctImage);

    waitKey(5); 

}

Main.cpp

int _tmain(int argc, _TCHAR* argv[])
{

//Enter file path
VideoSplitEngine myEngin;

myEngin.GetFilePath();


//Enter message
UserInfo input;

vector<int> myinput = input.UserInputList();


//Split video
myEngin.Start(myinput);


//Pause system (no auto exit)
system("pause");
}

I am unsure how to embed binary into pixel.

2014-07-10 03:41:21 -0600 received badge  Teacher (source)
2014-07-10 03:31:50 -0600 received badge  Self-Learner (source)
2014-07-10 03:30:25 -0600 answered a question C++ How to split video into 16 by 16 pixel for the whole frame?

This is the solution to do 16x16 and then 8x8.

for (int i = 0; i < height-16; i += 16) 
{ 

   for (int j = 0; j < width-16; j+= 16) 
   {
      Mat block = dctImage(Rect(j, i, 8, 8));

      vector<Mat> planes; 

      split(block, planes);
    }
}
2014-07-10 03:26:20 -0600 commented question C++ How to split video into 16 by 16 pixel for the whole frame?

@Haris Thank You. I have solve my problem with some help from the link you given.

2014-07-01 00:42:28 -0600 asked a question C++ How to split video into 16 by 16 pixel for the whole frame?

image description

Picture shows an example of a frame split into 16 by 16 and then 8 by 8. How do i split it in C++?

2014-06-17 04:14:45 -0600 commented answer How to cut selected timing from a video file? Please help?

Thank you. I would like to edit the code as "frameCount == stop_frame_count" will not match, it need to be in whole number.

void Watermark()

{

stop_frame_count = int(stop_frame_count+0.5);

frameCount=0;

while(1)
{
     frameCount++;

     capture.read(frame); 

     if(frameCount &gt;= start_frame_count &amp;&amp; frameCount &lt; stop_frame_count) 
     {
        VideoWriter.write(frame); 
     }

     else if(frameCount == stop_frame_count)
     {
       break;
     }
 }

}

2014-06-17 04:10:43 -0600 received badge  Supporter (source)
2014-06-17 04:10:40 -0600 received badge  Scholar (source)
2014-06-16 02:10:29 -0600 received badge  Organizer (source)
2014-06-15 23:25:15 -0600 received badge  Editor (source)
2014-06-15 23:09:40 -0600 asked a question How to cut selected timing from a video file? Please help?

I have a 5 min mp4 video file. I want to cut in between from 2 min to 3 min.

E.g. Video1.mp4 is 5 min long video, the output should be another file called Video2.mp4 that contain 2 min to 3 min from Video1.mp4.

What do i need to edit from the code below? Please help?


#include "stdafx.h" //By default

#include < string.h>

#include < stdio.h>

#include < stdlib.h>

#include "cv.h"

#include < highgui.h>

#include "cxcore.h"

#include <iostream> //To use cout and cin

using namespace cv; //To use VideoCapture

//Public file path

string fullPath;

VideoCapture capture(0);

void ExplicitWM()

{

//Explicit Watermark

//Input Message
char txt[100] = {'\0'};
cout << "Enter message to encode: " << endl;
cout<<"-----------------------"<< endl;
cin >> txt;


double dWidth = capture.get(CV_CAP_PROP_FRAME_WIDTH); //get the width of frames of the video
double dHeight = capture.get(CV_CAP_PROP_FRAME_HEIGHT); //get the height of frames of the video

cout << "Frame Size = " << dWidth << "x" << dHeight << endl;

Size frameSize(static_cast<int>(dWidth), static_cast<int>(dHeight));

//Save Video to desktop
string userProfile = getenv("userprofile");
string path = userProfile + "\\Desktop\\";
string saveVid;
getline (cin, saveVid);
string fullPath = path + saveVid;

//CV_FOURCC('P','I','M','1') is a MPEG-1 codec
VideoWriter oVideoWriter (fullPath + "SavedVid.avi", CV_FOURCC('P', 'I', 'M', '1'), 30, frameSize, true); //initialize the VideoWriter object 

if ( !oVideoWriter.isOpened() ) //if not initialize the VideoWriter successfully, exit the program
{
    cout << "ERROR: Failed to write the video" << endl;
}

while ( capture.isOpened() )
{
        Mat frame;

        bool bSuccess = capture.read(frame); // read a new frame from video

        imshow("Original Video", frame); //show the frame in "Original Video" window

        Mat imgW = frame;

        // cvScalar(255,255,255) = rgb
        // cvPoint(40,40) = x-y cord
        // 0.8 = font size
        putText(imgW, txt, cvPoint(400,400), CV_FONT_HERSHEY_COMPLEX, 0.8, cvScalar(255,255,255), 1, CV_AA);


        imshow("Watermarked Video", imgW); //show the frame of which watermark added

        oVideoWriter.write(imgW); //write the frame into the file

        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; 
        }
}

}

int main(int argc, char* argv[] )

{

cout<< endl;

cout << "Place video in Desktop and enter file name (e.g. vid.avi):" << endl;

cout<<"--------------------------------------"<< endl;

//Get user desktop file path

string userProfile = getenv("userprofile"); //GetEnvironmentVariable() is to get current userprofile (e.g."C:\Users\L30807")

string path = userProfile + "\\Desktop\\";

string vid;

getline (cin, vid);     //Prompt to input file name
fullPath = path + vid;
capture.open(fullPath); //Read video
cout<< endl;

if ( capture.isOpened() )
{
    char choice;
        cout<< "Choose option (a or b): "<< endl;
        cout<<"-----------------------"<< endl;
        cout<< "a.Encode Video "<<endl;
        cout<< "b.Decode Video "<<endl;
        cout<<"-----------------------"<< endl;
        cin >> choice;
        cout<< endl;

        if (choice== 'a')//Encode Video
        {
            int choiceEn;
            cout<< "Choose option (1 or 2): "<< endl;
            cout<<"-----------------------"<< endl;
            cout<< "1.Explicit Watermarking " <<endl;
            cout<< "2.Implicit Watermarking(DCT) "<<endl;
            cout<<"-----------------------"<< endl;
            cin >> choiceEn;
            cout<< endl;

            switch ( choiceEn ) 
            {
                case 1:         
                ExplicitWM();
                break;

                default:
                cout<<"Error: Wrong input. Exiting..." << endl;
                return 0;
            }
        }

        else if (choice== 'b') 
        { 

        }
}