0

I am working on a project using opencv to do some image processing on the video stream from android usb camera.Since I am not so good at java, I decided to use Qt on android with opencv-android-sdk. I get my video stream on android using libuvc examples:https://github.com/ktossell/libuvc/blob/master/src/example.c uvc_start_streaming(mDeviceHandle, &ctrl, cb, user_ptr, 0); my uvc code:

uvc_start_streaming(mDeviceHandle, &ctrl, cb, user_ptr, 0);
sleep(10);/* stream for 10 seconds */
uvc_stop_streaming(mDeviceHandle);

cb is the callback function of uvc_start_streaming and is also where I put my opencv image processing code and I also try to update Qt GUI widget in this function. Here is my cb funciton:

void cb(uvc_frame_t *frame, void *ptr) {   
    Mat img(480,640,CV_8UC3,frame->data,1280);
    //some image process here
    w->updatePreview(img);
}

w is a qt Mainwindow and my updatePreview funcion in mainwinow:

void MainWindow::updatePreview(Mat imgPreview)
{
    mpImageLabel->setPixmap(QPixmap::fromImage(Mat2QImage(imgPreview)));
}

My exception is to see a live video from my usb camera in mpImageLabel, but actually only the last frame of uvc streams showed in the mpImageLabel,other times the mpImageLabel is all blank.I guess the gui update function is hang up during the uvc streaming time. I searched for a while and have tried the method qApp->processEvent, but not work at all.Any ideas on this?

Dan Mašek
  • 17,852
  • 6
  • 57
  • 85

0 Answers0