问题描述
我有一个GoPro Hero 3+(黑色),它连接到视频捕获卡(AverMedia Game Broadcaster HD)。我只想在OpenCV中获得视频流。使用Logitech网络摄像头没有问题。使用的代码如下。
VideoCapture cap;
cap.open(0);
waitKey(300);
//cap.set(C_C0_CAP_PROP_FRAME_WIDTH,1280);
//cap.set(C_C0_CAP_PROP_FRAME_HEIGHT,720);
if(cap.isOpened()){
cout< 凸轮识别< endl
}
namedWindow(dst,1);
while(1){
垫子框架;
if(!cap.read(frame)){
std :: cout< 无法从视频流读取帧< std :: endl;
continue;
}
imshow(dst,frame);
[...]
}
使用GoPro,会出现以下情况:OpenCV能够打开VideoCapture(Cam已识别),但不能读取任何帧(只是灰色屏幕和输出:无法从视频流读取帧)。我也检查过这与frame.empty();。
我知道视频捕获卡工作正常,因为Unity打开一个WebCamTexture与GoPro流没有任何问题。我读了关于编解码器问题在OpenCV,所以我已经试图编译OpenCV与FFMPEG支持。
我使用OpenCV 2.48,Windows 7和Visual Studio 2013。
p>编辑:这里是libVLC解决方案的代码:
struct ctx
{
uint8_t * pixeldata;
std :: mutex imagemutex
};
static void display(void * data,void * id);
static void unlock(void * data,void * id,void * const * p_pixels);
static void * lock(void * data,void ** p_pixels);
struct ctx ctx;
libvlc_instance_t * inst;
libvlc_media_player_t * mp;
libvlc_media_t * m;
int main(int argc,char * argv [])
{
ctx.pixeldata = new uint8_t [1280 * 720 * 3]
char const * vlc_argv [] =
{
-vvv,
--no-audio,/ *跳过任何音轨* /
--no-xlib,/ *告诉VLC不使用Xlib * /
};
int vlc_argc = sizeof(vlc_argv)/ sizeof(* vlc_argv);
inst = libvlc_new(vlc_argc,vlc_argv);
const char * options [] =
{
:dshow-vdev = AVerMedia HD Capture,
:dshow-adev = none,
//:dshow-size = 1280x720,
:dshow-fps = 24,
:dshow-chroma = YUY2,
:dshow-video-input =,
:live-caching = 80=
:dshow-video-output = ,
NULL
};
m = libvlc_media_new_location(inst,dshow://);
for(const char ** opt = options; * opt; opt ++)
libvlc_media_add_option(m,* opt);
mp = libvlc_media_player_new_from_media(m);
libvlc_media_release(m);
libvlc_video_set_callbacks(mp,lock,unlock,display,& ctx);
libvlc_video_set_format(mp,RV24,1280,720,1280 * 3);
libvlc_media_player_play(mp);
namedWindow(all,1);
垫框架(720,1280,CV_8UC3);
while(1){
ctx.imagemutex.lock();
memcpy(gesamt.data,ctx.pixeldata,1280 * 720 * sizeof(uint8_t)* 3);
ctx.imagemutex.unlock();
imshow(all,gesamt);
if(waitKey(30)== 27)//等待'esc'键按下30ms。如果按下esc键,则断开循环
{
cout<< esc键由用户按下< endl
break;
}
}
libvlc_media_player_stop(mp);
libvlc_media_player_release(mp);
libvlc_release(inst);
delete [] ctx.pixeldata;
return 0;
}
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;
ctx-> imagemutex.unlock();
assert(id == NULL);
}
void * lock(void * data,void ** p_pixels){
struct ctx * ctx =(struct ctx *)data;
ctx-> imagemutex.lock();
* p_pixels = ctx-> pixeldata;
return NULL;
}
I have a GoPro Hero 3+ (Black) which is connected to a video capture card (AverMedia Game Broadcaster HD). I simply want to get the video stream in OpenCV. With a Logitech Webcam there are no problems. The used code is below.
VideoCapture cap;
cap.open(0);
waitKey(300);
//cap.set(CV_CAP_PROP_FRAME_WIDTH, 1280);
//cap.set(CV_CAP_PROP_FRAME_HEIGHT, 720);
if (cap.isOpened()){
cout << "Cam identified" << endl;
}
namedWindow("dst", 1);
while (1){
Mat frame;
if (!cap.read(frame)) {
std::cout << "Unable to read frame from video stream" << std::endl;
continue;
}
imshow("dst", frame);
[...]
}
With the GoPro the following happens: OpenCV is able to open the VideoCapture ("Cam identified") but can't read any frames (just a gray screen and the output: "Unable to read frame from video stream"). I also checked this with frame.empty();.
I know that the video capture card works correct because Unity opens a WebCamTexture with the GoPro stream without any issues. I read about codec problems in OpenCv and so I already tried to compile OpenCV with FFMPEG support. Now the recorded MP4-Videos of the GoPro can be displayed but the stream still doesn't work.
I use OpenCV 2.48, Windows 7 and Visual Studio 2013.
EDIT: Here is the code of libVLC solution:
struct ctx
{
uint8_t* pixeldata;
std::mutex imagemutex;
};
static void display(void *data, void *id);
static void unlock(void *data, void *id, void *const *p_pixels);
static void *lock(void *data, void **p_pixels);
struct ctx ctx;
libvlc_instance_t *inst;
libvlc_media_player_t *mp;
libvlc_media_t *m;
int main(int argc, char* argv[])
{
ctx.pixeldata = new uint8_t[1280 * 720 * 3];
char const *vlc_argv[] =
{
"-vvv",
"--no-audio", /* skip any audio track */
"--no-xlib", /* tell VLC to not use Xlib */
};
int vlc_argc = sizeof(vlc_argv) / sizeof(*vlc_argv);
inst = libvlc_new(vlc_argc, vlc_argv);
const char *options[] =
{
":dshow-vdev=AVerMedia HD Capture",
":dshow-adev=none",
//":dshow-size=1280x720",
":dshow-fps=24",
":dshow-chroma=YUY2",
":dshow-video-input=1",
":dshow-video-output=1",
":dshow-aspect-ratio=16\:9",
":live-caching=80",
NULL
};
m = libvlc_media_new_location(inst, "dshow://");
for (const char **opt = options; *opt; opt++)
libvlc_media_add_option(m, *opt);
mp = libvlc_media_player_new_from_media(m);
libvlc_media_release(m);
libvlc_video_set_callbacks(mp, lock, unlock, display, &ctx);
libvlc_video_set_format(mp, "RV24", 1280, 720, 1280 * 3);
libvlc_media_player_play(mp);
namedWindow("all", 1);
Mat frame(720, 1280, CV_8UC3);
while (1){
ctx.imagemutex.lock();
memcpy(gesamt.data, ctx.pixeldata, 1280 * 720 * sizeof(uint8_t) * 3);
ctx.imagemutex.unlock();
imshow("all", gesamt);
if (waitKey(30) == 27) //wait for 'esc' key press for 30ms. If 'esc' key is pressed, break loop
{
cout << "esc key is pressed by user" << endl;
break;
}
}
libvlc_media_player_stop(mp);
libvlc_media_player_release(mp);
libvlc_release(inst);
delete[] ctx.pixeldata;
return 0;
}
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;
ctx->imagemutex.unlock();
assert(id == NULL);
}
void *lock(void *data, void **p_pixels){
struct ctx *ctx = (struct ctx*)data;
ctx->imagemutex.lock();
*p_pixels = ctx->pixeldata;
return NULL;
}
I've had the same issues trying to stream a Sony action cam through an Avermedia capture card. One quick fix seems to be using DVDrive, which makes your capture card output look like a webcam. I've had success using this as a workaround.
这篇关于OpenCV和GoPro - VideoCapture流中的空帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!