Ask Your Question
1

how can i retrieve and process images from an ip camera ,working with c++

asked 2013-02-13 03:27:47 -0600

jihen gravatar image

hello; I am working on a project of detection and management of images captured from an ip camera. I can retrieve the image stream on my pc but haw can i separate images captured and treat every image on the c++ application

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
1

answered 2013-02-13 03:33:02 -0600

berak gravatar image

updated 2013-02-13 03:50:38 -0600

#include "opencv/cv.h"
#include "opencv/highgui.h"
using namespace cv;

int main()
{
    VideoCapture cap("http://213.157.112.12:8082/mjpg/video.mjpg?resolution=352x288");
    Mat frame; 
    namedWindow("video", 1);
    while(cap.isOpened()) {
        cap >> frame;
        if(!frame.data) break;
            //
            // now you can process process the frame data
            //
        imshow("video", frame);
        if(waitKey(30) >= 0) break;
    }   
    return 0;
}
edit flag offensive delete link more

Comments

This is a nice trick to do with OpenCV. However, beware that it's not officially supported, and you should never ever use it in production. For a school, hobby or demo app, that's great. Just make sure it works with your camera.

sammy gravatar imagesammy ( 2013-02-13 03:49:12 -0600 )edit

@sammy: Is there plan to support it?

Mathieu Barnachon gravatar imageMathieu Barnachon ( 2013-02-13 07:09:54 -0600 )edit
1

It happens to work when ffmpeg is the OpenCV backend, because it tries all its sources and codecs before giving up. I do not know what happens on other backends, and I have no clue on support plans 'cause I do not work for OpenCV. Although I would like :)

sammy gravatar imagesammy ( 2013-02-13 07:59:24 -0600 )edit
-1

answered 2018-03-09 22:04:33 -0600

Javier 23 gravatar image

updated 2018-03-12 00:39:40 -0600

include<opencv2 opencv.hpp="">

#include <opencv2/calib3d.hpp>
#include <opencv2/calib3d/calib3d.hpp>
#include <opencv2\videoio.hpp>
#include <opencv/highgui.h>
#include <opencv/cv.h> 
#include <opencv2/core/utility.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>
#include <cstdio>
#include <stdio.h>
#include <string> 
#include <sstream> 
#include <vector>
#include <algorithm>
#include <iterator>
#include <stdlib.h>
#include <iomanip>
#include <ctype.h>
#include <math.h>
#include <tchar.h>
#include <windows.h>
#include <vector>//
#include <thread>//
#include <concurrent_queue.h>//

using namespace std;
using namespace cv;
cv::Mat dst, cdst;
cv::Mat frame2, edges;
int main() {
    VideoCapture cap2("rtsp://admin:[email protected]:554/h264/ch1/main/av_stream");

    if (!cap2.isOpened()) {
        std::cout << "Error opening video stream or file" << std::endl;
        return -1;
    }
    else
    {


        std::cout << " la camara  IP 2 se abrio con exito!" << std::endl;
        cv::Mat frame;
    }


    //cv::VideoCapture vcap;

    /*cv::VideoCapture cap2("rtsp://admin:[email protected]:554/h264/ch1/main/av_stream");

    if (!cap2.isOpened()) {
        std::cout << "Error opening video stream or file" << std::endl;
        return -1;
    }
    else
    {


        std::cout << " la camara IP 2 se abrio con exito!" << std::endl;
        cv::Mat frame;
    }*/

    int frame_width = cap2.get(CV_CAP_PROP_FRAME_WIDTH);
    int frame_height = cap2.get(CV_CAP_PROP_FRAME_HEIGHT);
    VideoWriter video("data .avi", CV_FOURCC('M', 'J', 'P', 'G'), 30, Size(frame_width, frame_height));//Almacenamos video en disco

    for (;;) {

        cap2 >> frame2;
        /*if (!vcap.read(frame1)) {
        //std::cout << "No frame" << std::endl;
        cv::waitKey();
        }*/
            video.write(frame2);//GRABAMOS EL VIDEO
        //video.write(frame1);//GRABAMOS EL VIDEO



        /**cv::cvtColor(frame2, edges, CV_BGR2GRAY);
        GaussianBlur(edges, edges, Size(5, 5), 1.5, 1.5);//aplicamos filtro gaussiano con la finalidad de eliminar el ruido
        Canny(edges, edges, 0, 30, 3);//detectamos  los bordes del entorno*/

        cv::namedWindow("camera2");

        cv::resizeWindow("camera2", 520, 520);//asignamos la ventana 
        imshow("camera2", frame2);
        //imshow("image", edges);
        if (cv::waitKey(1) >= 0) break;
    }

    return 0;
}
edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-02-13 03:27:47 -0600

Seen: 2,777 times

Last updated: Mar 12 '18