我試圖使用libvlc
從網絡流中讀取幀,然後使用opencv
對這些幀應用一些處理。這是我使用的檢索幀代碼:opencv和libvlc不能在釋放模式下一起工作
struct ctx
{
IplImage* image;
HANDLE mutex;
uchar* pixels;
};
void *lock(void *data, void**p_pixels)
{
struct ctx *ctx = (struct ctx*)data;
WaitForSingleObject(ctx->mutex, INFINITE);
*p_pixels = ctx->pixels;
return NULL;
}
void display(void *data, void *id)
{
(void) data;
assert(id == NULL);
}
void unlock(void *data, void *id, void *const *p_pixels){
struct ctx *ctx = (struct ctx*)data;
// VLC just rendered the video, but we can also render stuff
uchar *pixels = (uchar*)*p_pixels;
cvShowImage("image", ctx->image);
ReleaseMutex(ctx->mutex);
assert(id == NULL); // picture identifier, not needed here
}
int main()
{
cvNamedWindow("image", CV_WINDOW_AUTOSIZE);
libvlc_media_t* media = NULL;
libvlc_media_player_t* mediaPlayer = NULL;
//char const* vlc_argv[] = {"--plugin-path", "C:\\Users\\Oscar\\Documents\\libvlc\\vlc-1.1.4"};
libvlc_instance_t* instance = libvlc_new(0,NULL);
mediaPlayer = libvlc_media_player_new(instance);
media = libvlc_media_new_location(instance, "rtsp://134.202.84.79:554/user=a&password=abcdef&channel=6&stream=0.sdp/");
struct ctx* context = (struct ctx*)malloc(sizeof(*context));
context->mutex = CreateMutex(NULL, FALSE,NULL);
//context->image = cvCreateImage(cvSize(libvlc_video_get_height(mediaPlayer), libvlc_video_get_width(mediaPlayer)), IPL_DEPTH_8U, 4);
context->image = cvCreateImage(cvSize(640,480), IPL_DEPTH_8U, 4);
context->pixels = (unsigned char *)context->image->imageData;
libvlc_media_player_set_media(mediaPlayer, media);
libvlc_video_set_callbacks(mediaPlayer, lock, unlock, display, context);
libvlc_video_set_format(mediaPlayer, "RV32", 640, 480, 640*4);
libvlc_media_player_play(mediaPlayer);
while(true)
{
if (waitKey(30)==27)
{
break;
}
}
return 0;
}
的問題是,這個在調試模式下工作時,工作正常,但當我切換到發佈模式,它說:
程序入口點cvCreateImage不能位於動態鏈接庫libvlc.dll中。
我也嘗試更改鏈接器優化標誌,但問題仍然存在。
或者你可以只使用正確的產生libvlc.lib:https://code.google.com/p/vc-libvlc/downloads/list – RSATom