- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have sample code for testing the camera streaming from the fx3 when connecting the camera, I have to perform the interrupt transfer by the side when the camera starts streaming,
I have an fx3 board and camera connected, I have used the libuvc and libusb libraries with opencv, I have used in the code to do,
#include <stdio.h>
#include <opencv/highgui.h>
#include <opencv2/core.hpp>
#include <opencv2/opencv.hpp>
#include "libuvc/libuvc.h"
#include "libuvc/libuvc_internal.h"
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <iostream>
#include <opencv2/imgproc.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/opencv.hpp>
#include <thread>
using namespace std;
using namespace cv;
void cb(uvc_frame_t *frame, void *ptr) {
uvc_frame_t *bgr;
uvc_error_t ret;
IplImage* cvImg;
int wid = frame->width;
int hei = frame->height;
unsigned short data16[wid*hei];
unsigned char * bytedata = (unsigned char*) frame->data;
for(int ii=0; ii < wid*hei; ii++) {
data16[ii] = (unsigned short) (bytedata[2*ii]) | (unsigned short) (bytedata[2*ii+1] << :sunglasses: ;
}
cv::Mat Bayer( hei, wid, CV_16UC1, (void*) data16);
double min, max;
cv::minMaxLoc(Bayer, &min, &max);
cv::Mat bgrmat(wid,hei,CV_16UC3);
cv::cvtColor(Bayer, bgrmat, CV_BayerBG2RGB);
cv::pyrDown(bgrmat,bgrmat);
cv::pyrUp(bgrmat,bgrmat);
bgrmat.convertTo(bgrmat,CV_8UC3);
Bayer.convertTo(Bayer,CV_8UC3);
#if 0
#endif
cv::namedWindow("Test", CV_WINDOW_AUTOSIZE);
cv::imshow("Test", bgrmat);
cv::waitKey(1);
}
void task1() {
struct libusb_device_handle *usb_devh;
uvc_device_handle_t *internal_devh;
struct libusb_device_descriptor desc;
uvc_device_t *dev;
int result;
int recv;
unsigned char data_in[4];
result = libusb_open(dev->usb_dev, &usb_devh);
fprintf(stderr, " result %d\n", result);
}
int main(int argc, char **argv) {
uvc_context_t *ctx;
uvc_error_t res;
uvc_device_t *dev;
uvc_device_handle_t *devh;
uvc_stream_ctrl_t ctrl;
struct libusb_device_handle *usb_devh;
struct libusb_device_descriptor desc;
res = uvc_init(&ctx, NULL);
if (res < 0) {
uvc_perror(res, "uvc_init");
return res;
}
puts("UVC initialized");
res = uvc_find_device(
ctx, &dev,
0, 0, NULL);
if (res < 0) {
uvc_perror(res, "uvc_find_device");
} else {
puts("Device found");
res = uvc_open(dev, &devh);
if (res < 0) {
uvc_perror(res, "uvc_open");
} else {
puts("Device opened");
uvc_print_diag(devh, stderr);
res = uvc_get_stream_ctrl_format_size(
devh, &ctrl, UVC_FRAME_FORMAT_YUYV, 400, 400, 30);
uvc_print_stream_ctrl(&ctrl, stderr);
if (res < 0) {
uvc_perror(res, "get_mode");
} else {
int dummy;
int result;
res = uvc_start_streaming(devh, &ctrl, cb,&dummy, 0);
if (res < 0) {
uvc_perror(res, "start_streaming");
} else {
puts("Streaming for 10 seconds...");
uvc_error_t resAEMODE = uvc_set_ae_mode(devh, 1);
uvc_perror(resAEMODE, "set_ae_mode");
int i;
unsigned char data_in[4];
int recv;
while(1){
result = libusb_interrupt_transfer(devh->usb_devh, 0x82, data_in, 4, &recv, 1000);
printf("%d",result);
for(int i = 0; i < recv; i++)
{
printf("%02x ",data_in[i]);
}
printf("\n");
}
sleep(1);
// }
sleep(200);
uvc_stop_streaming(devh);
puts("Done streaming.");
}
}
uvc_close(devh);
puts("Device closed");
}
uvc_unref_device(dev);
}
uvc_exit(ctx);
puts("UVC exited");
return 0;
}
I have tested the interrupt transfer and camera streaming separately, which is working fine.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
What issue are you exactly facing when you tried to do the transfer?
Regards,
- Madhu Sudhan