L
L
lPestl2014-01-15 10:08:34
Programming
lPestl, 2014-01-15 10:08:34

How to upload an image to IplImage from an ip camera without first saving it to disk?

Perhaps this is an elementary question, but still I have been suffering for an hour. Tell me how can I directly capture a frame from an IP camera in IplImage without saving it to an intermediate jpg file?
Everything works if the image is first saved, and then loaded into IplImage from the screw:

if ( URLDownloadToFileA(NULL,LPCSTR(m_url),LPCSTR(filename),0,NULL) == S_OK ) {
    IplImage *img = cvLoadImage(filename, CV_LOAD_IMAGE_COLOR);
    //...
}

where m_url is a string containing the snapshot request url (for example: http://admin:[email protected]/image.jpg ) and filename is the file name.
In the above example, everything works, the image is saved and then loaded into IplImage *img.
But I would really like to get the image right away, but the next move doesn't work:
//if ( URLDownloadToFileA(NULL,LPCSTR(m_url),LPCSTR(filename),0,NULL) == S_OK ) {
    IplImage *img = cvLoadImage(/*filename*/m_url, CV_LOAD_IMAGE_COLOR);
    //...
//}

I tried to google, but I can't find anything useful for more than an hour. Please, help out and tell me the solution.

Answer the question

In order to leave comments, you need to log in

5 answer(s)
L
lPestl, 2014-01-16
@lPestl

There is a second day. Perhaps tell me at least a solution with saving the image to the buffer and loading it from the buffer? Or with saving the picture in cash and then accessing it???

L
lPestl, 2014-01-16
@lPestl

The second day is coming to an end, and no one even offered a simple logical way out of this situation! I don't even ask for a code!

L
lPestl, 2014-01-17
@lPestl

It was the third day...

D
Dmitry, 2014-01-18
@peleron

The conversion of IplImage to JPG is implemented using the cvEncodeImage procedure - at the output we get a completely finished JPG - with all attributes and meta-information.
The reverse procedure is done using the cvDecodeImage function
Official documentation is not...
An example, but for the ancient opencv
My code for encoding to JPG - unfortunately I did not find the reverse procedure, but the main thing is to understand JPG images are transmitted through CvMat structures, the main fields of which are data. ptr and cols

#define MAX_JPEG_IMAGE_SIZE	1000000
int jpeg_params[] = { CV_IMWRITE_JPEG_QUALITY, 50, 0 };
CvMat* encodedMat;
IplImage* frame = 0;
CvCapture *capture;
int image_length;
unsigned char jpeg_image[MAX_JPEG_IMAGE_SIZE];
{
    cvWaitKey(100);
    frame = cvQueryFrame(capture);
    if (frame == NULL) {
      printf("ERROR %s() Can't query frame from camera.\n", __FUNCTION__);
      break;
    }
    encodedMat = cvEncodeImage(".jpeg", frame, jpeg_params);
    if (encodedMat == NULL) {
      printf("ERROR %s() Can't encode frame.\n", __FUNCTION__);
      break;
    }
    if (encodedMat->cols > MAX_JPEG_IMAGE_SIZE) {
      printf("ERROR %s() Size of encoded image (%d) exceeded maximum buffer size (%d).\n",
          __FUNCTION__, encodedMat->cols, MAX_JPEG_IMAGE_SIZE);
      break;
    }
    image_length = encodedMat->cols;
    memcpy(jpeg_image, encodedMat->data.ptr, image_length);
    cvReleaseMat(&encodedMat);
}

B
Brutalis, 2014-05-27
@Brutalis

I am using the following method. under windows there is such a thing IP Camera DS Filter and graphstudio / here it is described to set up all this,
the picture itself, we get this

{
    {
    CvCapture* capture =  cvCaptureFromCAM( KAMIND );// где  KAMIND индекс камеры в системе
    //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    if(capture == NULL)// Если камер не обнаружено
     assert( capture );

                          cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, 320);//1280);
                          cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT,240);//960);
                           int counter=0;
                           char filename[512];
                            while(true){
                                    // получаем кадр
                                    frame = cvQueryFrame( capture );
                                    // показываем

                                     cvShowImage("Video", frame);

                                    char c = cvWaitKey(33);
                                    if (c == 27) {break;} // нажата ESC
                                           else if(c == 13) { // Enter сохраняем кадр в файл
                                            sprintf(filename, "Image%d.jpg", counter);
                                            printf("[i] capture... %s\n", filename);
                                            cvSaveImage(filename, frame);cvSaveImage(filename, dst);
                                            counter++;}}
                            // освобождаем ресурсы
                            cvReleaseCapture( &capture );
                            cvDestroyWindow("capture");cvDestroyAllWindows();
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question