Ask Your Question

ashish's profile - activity

2014-10-22 14:47:56 -0600 asked a question about opencv 2 video opening error in visualstudio 2012

in this programme i want to open the videofile that is in d drive so, i have written below code: ---------------------------------

#include "opencv2/highgui/highgui.hpp"
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char* argv[])
{
VideoCapture cap("D://ashish.mp4");
if(!cap.isOpened())
{system("pause");
cout<<"error "<<endl;
return 0;
}
namedWindow("MyVideo",CV_WINDOW_AUTOSIZE);
while (1)
{
Mat frame;
bool bSuccess = cap.read(frame); // read a new frame from video
if (!bSuccess) //if not success, break loop
{
cout << "Cannot read a frame from video stream" << endl;
break;
}
imshow("MyVideo", frame); //show the frame in "MyVideo" window
if (waitKey(30) == 27) //wait for 'esc' key press for 30ms. If 'esc' key is pressed, break loop
{
cout << "esc key is pressed by user" << endl;
break;
}
}
return 0;

}

i'm getting an warning : error opening file <../../modules/highgui/src/cap_ffmpeg_impl.hpp:545>

2014-09-19 04:00:33 -0600 commented question can't creat multiple trackbars in opencv2.4.9 with visual studio 2012

in output image is shown with only one trackbar but as i slide the slider i get messege Unhandled exception at 0x00C13964 in mynewopen.exe: 0xC0000005: Access violation reading location 0x00000000

2014-09-19 03:59:26 -0600 commented answer can't creat multiple trackbars in opencv2.4.9 with visual studio 2012

in output image is shown with only one trackbar but as i slide the slider i get messege

Unhandled exception at 0x00C13964 in mynewopen.exe: 0xC0000005: Access violation reading location 0x00000000

2014-09-18 14:43:42 -0600 asked a question can't creat multiple trackbars in opencv2.4.9 with visual studio 2012

Hello! i'm biggner in programming. I've copied this code in visual studio 2012,

#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
using namespace std;
using namespace cv;
Mat src;
void MyCallbackForBrightness(int iValueForBrightness, void *userData)
{
    Mat dst;
    int iValueForContrast = *( static_cast<int*>(userData) );
    //Calculating brightness and contrast value
    int iBrightness = iValueForBrightness - 50;
    double dContrast = iValueForContrast / 50.0;
    //Calculated contrast and brightness value
    cout << "MyCallbackForBrightness : Contrast=" << dContrast << ", Brightness=" << iBrightness << endl;
    //adjust the brightness and contrast
    src.convertTo(dst, -1, dContrast, iBrightness);
    //show the brightness and contrast adjusted image
    imshow("My Window", dst);
}

void MyCallbackForContrast(int iValueForContrast, void *userData)
{
    Mat dst;
    int iValueForBrightness = *( static_cast<int*>(userData) );
    //Calculating brightness and contrast value
    int iBrightness = iValueForBrightness - 50;
    double dContrast = iValueForContrast / 50.0;
    //Calculated contrast and brightness value
    cout << "MyCallbackForContrast : Contrast=" << dContrast << ", Brightness=" << iBrightness << endl;
    //adjust the brightness and contrast
    src.convertTo(dst, -1, dContrast, iBrightness);
    //show the brightness and contrast adjusted image
    imshow("My Window", dst);
}

int main(int argc, char** argv)
{
    // Read original image
    IplImage *dd = cvLoadImage("D:\\ashish.png");
    Mat src(dd);
    //if fail to read the image
    if (src.data == false)
    {
        cout << "Error loading the image" << endl;
        return -1;
    }
    // Create a window
    namedWindow("My Window", 1);
    int iValueForBrightness = 50;
    int iValueForContrast = 50;
    //Create track bar to change brightness
    createTrackbar("Brightness", "My Window", &iValueForBrightness, 100, MyCallbackForBrightness, &iValueForContrast);
    //Create track bar to change contrast
    createTrackbar("Contrast", "My Window", &iValueForContrast, 100, MyCallbackForContrast, &iValueForBrightness);
    imshow("My Window", src);
   // Wait until user press some key
    waitKey(0);
    return 0;
}

in output image is displayed on the window only with "one"(not two as in code) trackbar but as i changed the position of slider on that it give following error

Unhandled exception at at 0x75CCB727 in mynewopen.exe: Microsoft C++ exception: cv::Exception at memory location 0x0036F4CC.

---and also the name of the trackbar that is in code is not same as in displayed output it shows some random symbols.

2014-09-18 14:22:49 -0600 asked a question i have a problem of recording of video in opencv2.4.9 with visualstudio2012
#include "opencv2/highgui/highgui.hpp"
#include"opencv2/core/core.hpp"
#include"opencv2/imgproc/imgproc.hpp"
#include<stdlib.h>
#include <iostream>

using namespace cv;
using namespace std;
int main(int argc, char* argv[])
{
    VideoCapture cap(0);
    // open the video camera no. 0

    if (!cap.isOpened()) // if not success, exit program
    {
        cout << "ERROR: Cannot open the video file" << endl;
        return -1;
    }
    namedWindow("My",CV_WINDOW_AUTOSIZE); 
    double j=cap.get(CV_CAP_PROP_FPS);
    double width=cap.get(CV_CAP_PROP_FRAME_WIDTH);
    double height=cap.get(CV_CAP_PROP_FRAME_HEIGHT);
    cout<<width<<endl;
    Size framesize(static_cast<int>(width),static_cast<int>(height));
    VideoWriter ovid("D:\ashish.avi",CV_FOURCC('P','I','M','1'),20,framesize,true);
    cout<<framesize;
    if(!ovid.isOpened())
    {

        system("pause");
        return -1;

    }

    while (1)
    {
        Mat frame;
        cap>>frame;
        ovid.write(frame);
        imshow("My", frame); //show the frame in "MyVideo" window
        if (waitKey(10) == 27) //wait for 'esc' key press for 30ms. If 'esc' key is pressed, break loop
        {
            cout << "esc key is pressed by user" << endl;
            break;
        }
    }
    return 0;
}

above code executes with no warning but no video is displays on window as well as no recording happens.