Problem black image
Hi, i use "smartgaze" trishume's project for eyetribe on github. The programmer of this project take raw files from hardware. I use this code in virtual machine kubuntu on virtualbox. I view a black window and with some prints i see that the function runs one time. This hardware use usb 3.0 but the code of this project is really simple. I think that i have problem with throughput of hardware but it work with official program on windows. The minimum fps value supported is 27 and max 60. This project use opencv, liusb, libuvc libraries.
#include "libuvc/libuvc.h"
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <stdio.h>
#include <unistd.h>
#include <stdint.h>
static const int kCaptureWidth = 1536; //resolution
static const int kCaptureHeight = 1024;
static const int kCaptureFPS = 60; //frame/s
static const char kCurveData[8] = {250, 0, 240, 0, 250, 0, 240, 0};
/* This callback function runs once per frame. Use it to perform any
* quick processing you need, or have it put the frame into your application's
* input queue. If this function takes too long, you'll start losing frames. */
void cb(uvc_frame_t *frame, void *stopPtr) {
cv::Mat cvFrame(frame->height, frame->width, CV_16UC1, frame->data);
cvFrame.convertTo(cvFrame, CV_16U, 100, 0);
imshow("main", cvFrame);
}
void setLights(uvc_device_handle_t *devh, int lights) {
uvc_set_ctrl(devh, 3, 3, (void*)(&lights), 2);
}
void setupParams(uvc_device_handle_t *devh) {
uvc_set_ctrl(devh, 3, 4, (void*)(kCurveData), 8);
}
int main(int argc, char **argv) {
uvc_context_t *ctx;
uvc_device_t *dev;
uvc_device_handle_t *devh;
uvc_stream_ctrl_t ctrl;
uvc_error_t res;
/* Initialize a UVC service context. Libuvc will set up its own libusb
* context. Replace NULL with a libusb_context pointer to run libuvc
* from an existing libusb context. */
res = uvc_init(&ctx, NULL);
if (res < 0) {
uvc_perror(res, "uvc_init"); //error initialize
return res;
}
cv::namedWindow("main",CV_WINDOW_NORMAL);
puts("UVC initialized");
/* Locates the first attached UVC device, stores in dev */
res = uvc_find_device(
ctx, &dev,
10667, 251, NULL); /* filter devices: vendor_id, product_id, "serial_num" */
if (res < 0) {
uvc_perror(res, "uvc_find_device"); /* no devices found */
} else {
puts("Device found");
/* Try to open the device: requires exclusive access */
res = uvc_open(dev, &devh);
if (res < 0) {
uvc_perror(res, "uvc_open"); /* unable to open device */
} else {
puts("Device opened");
/* Print out a message containing all the information that libuvc
* knows about the device */
uvc_print_diag(devh, stderr);
/* Try to negotiate a YUYV stream profile */
res = uvc_get_stream_ctrl_format_size(
devh, &ctrl, /* result stored in ctrl */
UVC_FRAME_FORMAT_YUYV, /* YUV 422, aka YUV 4:2:2. try _COMPRESSED */
kCaptureWidth, kCaptureHeight, kCaptureFPS /* width, height, fps */
);
/* Print out the result */
uvc_print_stream_ctrl(&ctrl, stderr);
if (res < 0) {
uvc_perror(res, "get_mode"); /* device doesn't provide a matching stream */
} else {
setLights(devh, 0xb1111);
int stop = 0;
/* Start the video stream. The library will call user function cb:
* cb(frame, (void*) 0)
*/
res = uvc_start_streaming(devh, &ctrl, cb, (void*)(&stop), 0);
if (res < 0) {
uvc_perror(res, "start_streaming"); /* unable to start stream */
} else {
puts("Streaming...");
// uvc_set_ae_mode(devh, 1); /* e.g., turn on auto exposure */
while(true) {
int key = cv::waitKey(10);
if((char)key == 'q') {
break;
}
if((char)key == 'o ...
This error has nothing to do with OpenCV. OpenCV is only used to display the image, and you have probably a problem with the capturing.
You can check that the streaming works by adding the line:
putc('*');
in the cb function. If the frames are grabbed, it should fill the terminal window with*
.