Ask Your Question

Revision history [back]

Unable to output gray scale video using opencv on beaglebone black

I'm trying to record a video using webcam and convert it to gray scale video using opencv on beablebone black. I am able to create the video in color but when I try to convert it to gray scale it is not working. Its just creating a .avi file with 6kB size. Below is the code I'm using. TIA

 #include "opencv2/opencv.hpp" 
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <time.h>
using namespace std;
using namespace cv;
#define MAX_FRAME 40

int main(int, char**)
{
    // capturing video feed as vcap
    VideoCapture vcap(0);
    // verifying video feed and printing an error message in case of failure
    if(!vcap.isOpened())
    {
        cout << "Error opening video stream or file" << endl; return -1;
    }
    // We multiply the number of pixels (in both x and y) by this value
    double sizeMultiplier = .25;
    // getting the width and height of the frames
    int frame_width = vcap.get(CV_CAP_PROP_FRAME_WIDTH);
    int frame_height = vcap.get(CV_CAP_PROP_FRAME_HEIGHT);
    frame_width = frame_width*sizeMultiplier;
    frame_height = frame_height*sizeMultiplier;
    // recording the video as out_canny.avi
    VideoWriter video("output.avi", CV_FOURCC('M','J','P','G'), 5, Size(frame_width,frame_height),true);


     Mat frame, frame_small, gray;
    for(int numFrame = 0; numFrame < MAX_FRAME; numFrame++)
    {
        vcap >> frame; // video capturing into the matrix frame
        //cvtColor(frame, gray, CV_BGR2GRAY); 
        //blur(frame, frame, Size(3, 3));
        //Canny(frame, frame, 0, 30, 3);
        resize(frame,frame_small,Size(), sizeMultiplier,sizeMultiplier);
        cvtColor(frame_small, frame_small, CV_BGR2GRAY); //Not Working
        video.write(frame_small); // recording the resulting video
    }
    //vcap.release();
    return 0;
}