Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
CvCapture *camera= cvCaptureFromFile("rtsp://192.168.1.19:554/0/1:1/main");
    if (camera==NULL)
        printf("camera is null\n");
    else
        printf("camera is not null");

    cvNamedWindow("img");

    while (cvWaitKey(10)!=atoi("q")){

        IplImage *img=cvQueryFrame(camera);
        cvShowImage("img",img);
    }
    cvReleaseCapture(&camera);

This is the code i use to access my IP camera. I want this to convert iplimage type to Mat type to do my project HOG human detection. so providing a neccassory code in c++ for this would be a big help. I have tried Mat mtx(img); imshow("from IP camera", mtx); to convert didnt work in streaming.
Posted
Updated 22-Feb-14 18:05pm
v2

1 solution

From here http://docs.opencv.org/modules/core/doc/basic_structures.html[^] we get:

Mat::Mat(const IplImage* img, bool copyData=false)

img - Pointer to the old-style IplImage image structure. By default, the data is shared between the original image and the new matrix. But when copyData is set, the full copy of the image data is created.

So:

C++
IplImage *img=cvQueryFrame(camera);
cvShowImage("img",img);
Mat imgMat(img);


This is the way to convert.

Then:
C++
namedWindow( "Display window", WINDOW_AUTOSIZE );// Create a window for display.
imshow( "Display window", imgMat );              // Show our image inside it
 
Share this answer
 
v3
Comments
DaksithaW 23-Feb-14 3:06am    
Thank you so much for the help. I am getting an error, when i debug the error occurs when it tried to execute,
namedWindow( "Display window", WINDOW_AUTOSIZE );// Create a window for display.
imshow( "Display window", imgMat ); // Show our image inside it
error : Unhandled exception at 0x004a0058 in HOG descriptor.exe: 0xC0000005: Access violation reading location 0x2079616c.
any help ?
[no name] 23-Feb-14 3:15am    
Are you doing a histogram somewhere? If you read the error message it does not seem related to the code above.
1. To test the above code you should use a small test program.
2. Then you need to use your debugger to step through your program to find where it is breaking.
DaksithaW 13-Apr-14 2:47am    
Yes thank you so much for the help. I found the error it was a configuration error. initially i was using 32 bit then i changed to 64 bit windows 7. then i did configure with release instead debug then everything worked fine. thank you for the support

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900