Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
This is the code used to access my IP camera using lan port. (first code works fine). What I need is to get image with Mat(C++) structure. Code number 2 shows what I have done to using Mat structure but when I debug the program, execute cv::namedWindow("Frame"); and then breaks the code giving out an Unhandled exception which shows bellow.
My Final requirement is to get this job done using Mat instead of iplimage. tip or an appropriate code would be great since I am doing a project on Human detection using HOG. thanks.
C++
#include "stdafx.h"
#include <stdio.h>
#include <opencv2/opencv.hpp>
#include <iostream>
#include <stdio.h>
#include "opencv.hpp"

int main(){

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



C#
int main(int argc, char* argv[])
{
        cv::Ptr<CvCapture> capture = cvCaptureFromFile("rtsp://192.168.1.19:554/0/1:1/main");
        cv::namedWindow("Frame");
        for (;;)
        {
            cv::Mat frame = cvQueryFrame(capture);
            cv::imshow("Frame", frame);
            if (cv::waitKey(1) >= 0)
            break;
        }
    return 0;
}


Error:
Unhandled exception at 0x00660598 in Hog with Web cam.exe: 0xC0000005: Access violation reading location 0xcccc0065.
Posted
Updated 13-Mar-14 23:46pm
v3

You probably have to delete your cv::Ptr at some point of time.
 
Share this answer
 
Comments
DaksithaW 15-Mar-14 0:55am    
so to do that I need to change it to cv::VedioCapture format right. this address is not working. I mean when i use my ip address in cv:: format it does not read any fram from the camera.
 
Share this answer
 
Comments
DaksithaW 15-Mar-14 0:53am    
"rtsp://192.168.1.19:554/0/1:1/main" this is my ip address and its password protected. This was taken from the user manual of the camera. apparently it was given to stream rtsp in vlc so to use this with cv::VideoCapture vcap; do i need to change the format or add a dummy tail ? any tip thanks.
[no name] 15-Mar-14 3:50am    
Have you tested rtsp with some other software? Is rtsp enabled? The password string will be in there (1:1)? - have you used correct password? Should all be in technical documentation for camera.
DaksithaW 15-Mar-14 8:08am    
Yes it is working properly and i can access my camera using opencv but the problem to further proceed I need output image in Mat form that is why. the ip address is correct.
[no name] 15-Mar-14 8:36am    
What's the question?
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