Ask Your Question

rohitmulay's profile - activity

2020-11-14 09:51:50 -0500 received badge  Popular Question (source)
2017-07-13 04:58:48 -0500 commented question How do i convert a Grayscale video to a Tensor?

Yes! i want to stack it, how do i use vector/list of matrices? I want to access the 3D matrix to perform some mathematical operations on it. @alkasm

2017-07-13 04:40:57 -0500 asked a question How do i convert a Grayscale video to a Tensor?

I have written a code which converts a RGB video to Grayscale and now I want to convert it to a tensor. I just gave cout<<graymat <<"\n"; in my code and I'm getting an output but i guess it is in matrix but not in tensor. To compile this program i used the command g++ `pkg-config --cflags opencv` vid.cpp `pkg-config --libs opencv` -fopenmp and ./a.out to Run it and I'm using a 2 sec video in my code.

The following is the code:

#include "opencv2/highgui/highgui.hpp"
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
#include <omp.h>

using namespace cv;
using namespace std;

int main(int argc, char* argv[])
{
double total_non_parallel = omp_get_wtime();
    VideoCapture cap("/home/rmulay17/Downloads/2.mp4"); // open the video file for reading

    if ( !cap.isOpened() )  // if not success, exit program
    {
         cout << "Cannot open the video file" << endl;
    }


    namedWindow("MyVideo",CV_WINDOW_AUTOSIZE); //create a window called "MyVideo"

  while(1)
   {
        cv::Mat frame;
    cv::Mat graymat;

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

        if (!bSuccess) //if not success, break loop
        {
                   //     cout << "Cannot read the frame from video file" << endl;
                       break;
        }

         cv::cvtColor(frame,graymat,cv::COLOR_BGR2GRAY); //Converts RGB to Grayscale
         Mat float_mat;
         graymat.convertTo( float_mat,CV_8U);

         imshow("MyVideobnw", graymat);

     cout<<graymat <<"\n"; // This Prints Frames of Grayscale video on terminal in matrix format
     double fps = cap.get(CV_CAP_PROP_FPS);
         cout << "Frame per seconds : " << fps << endl;
        imshow("MyVideo", frame); //show the frame in "MyVideo" window

//FileStorage file("/home/rmulay17/Desktop/Filevid.txt",FileStorage::WRITE);
//file<<graymat; //NOT WORKING!

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

    }
    printf("\n");
    printf("%lf is the total time taken\n",total_non_parallel);
    printf("\n");
    return 0;

}

Can someone help me generate a tensor from a grayscale video?

2017-07-10 03:35:28 -0500 commented answer I'm Trying to convert RGB video to Grayscale using OpenCV in C++, but i'm getting an error in my code. Can anyone help me with the code?

Yes, that is exactly what i wanted, this is working fine! Thank You so much! @berak

2017-07-10 03:34:04 -0500 received badge  Supporter (source)
2017-07-10 03:31:26 -0500 received badge  Scholar (source)
2017-07-10 03:09:12 -0500 asked a question I'm Trying to convert RGB video to Grayscale using OpenCV in C++, but i'm getting an error in my code. Can anyone help me with the code?

This is the code i used:

#include "opencv2/highgui/highgui.hpp"
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main(int argc, char* argv[])
{
    VideoCapture cap("/home/rmulay17/Downloads/vpb.mp4"); // open the video file for reading

    if ( !cap.isOpened() )  // if not success, exit program
    {
         cout << "Cannot open the video file" << endl;
         return -1;
    }

    //cap.set(CV_CAP_PROP_POS_MSEC, 300); //start the video at 300ms

    double fps = cap.get(CV_CAP_PROP_FPS); //get the frames per seconds of the video

     cout << "Frame per seconds : " << fps << endl;

    namedWindow("MyVideo",CV_WINDOW_AUTOSIZE); //create a window called "MyVideo"

  while(1)
   {
        cv::Mat frame;
    cv::Mat graymat;

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

        if (!bSuccess) //if not success, break loop
        {
                        cout << "Cannot read the frame from video file" << endl;
                       break;
        }
         cvCvtColor(frame,graymat,CV_BGR2GRAY);
         graymat.convertTo( Mat,CV_32F);
         imshow("MyVideobnw", graymat);

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

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

}

This is the error I'm getting:

video.cpp: In function ‘int main(int, char**)’:

video.cpp:38:46: error: cannot convert ‘cv::Mat’ to ‘const CvArr* {aka const void}’ for argument ‘1’ to ‘void cvCvtColor(const CvArr, CvArr*, int)’ cvCvtColor(frame,graymat,CV_BGR2GRAY);

^ video.cpp:39:32: error: expected primary-expression before ‘,’ token graymat.convertTo( Mat,CV_32F);

Somebody please help me and give me an solution to this problem!

Thank You in advance.