1
我擁有VideoSec IP攝像頭,並在嵌入式Linux NPE控制器上運行守護程序。守護進程需要從IP相機革蘭氏圖像,即一部分與在標準方式的libcurl實現,並與軸相機工作得很好:從MJPEG流中獲取一個圖像幀
static size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) {
size_t written = fwrite(ptr, size, nmemb, stream);
return written;
}
void refreshCameraImage(char *target, char *url)
{
CURL *image;
CURLcode imgresult;
FILE *fp;
image = curl_easy_init();
if (image)
{
fp = fopen(target, "wb");
if(fp == NULL)
printf("\nFile cannot be opened");
curl_easy_setopt(image, CURLOPT_URL, url);
curl_easy_setopt(image, CURLOPT_WRITEFUNCTION, NULL);
curl_easy_setopt(image, CURLOPT_WRITEDATA, fp);
imgresult = curl_easy_perform(image);
if(imgresult)
{
printf("\nCannot grab the image!");
}
}
curl_easy_cleanup(image);
fclose(fp);
}
問題的VideoSec相機是,我不能定義任何JPEG流,僅MJPEG 。 所以,我需要一種方法從libcurl中只抓取mjpeg流中的一幀。 OpenCV不是一個選項。
我已經在Content-Length的幫助下做了這個工作,使用套接字而不是curl,但是這種方法是正確的。 – Mel 2013-04-29 15:18:13