Skip to content

Commit

Permalink
reorganizing
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfuzz committed May 1, 2016
1 parent 60d2dc6 commit fbfc732
Show file tree
Hide file tree
Showing 7 changed files with 236 additions and 205 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.o
main
4 changes: 3 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ LDFLAGS="-L/usr/local/lib"
LIBRARY_PATH="/usr/local/lib"

gcc $CFLAGS -c main.c
gcc $LDFLAGS -o main main.o -luvc -lopencv_highgui -lopencv_core -lopencv_imgproc
gcc $CFLAGS -c leap.c
gcc $CFLAGS -c leap_calibrate.c
gcc $LDFLAGS -o main main.o leap.o -luvc -lopencv_highgui -lopencv_core -lopencv_imgproc
170 changes: 170 additions & 0 deletions leap.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
#include <pthread.h>
#include "leap.h"

void cb(uvc_frame_t *frame, void *ptr) {
leap_t *leap = (leap_t *)ptr;
uvc_error_t ret;
uint8_t *data = (uint8_t *)frame->data;

if(leap->left == NULL)
{
leap->left = cvCreateImage(
cvSize(frame->width, frame->height),
IPL_DEPTH_8U,
1);

leap->right = cvCreateImage(
cvSize(frame->width, frame->height),
IPL_DEPTH_8U,
1);

leap->i = cvCreateImage(
cvSize(frame->width, frame->height),
IPL_DEPTH_8U,
1);
}

pthread_mutex_lock(&leap->lock);

{
int i,j;
for(i=0;i<frame->height;i++)
{
for(j=0;j<frame->width;j++)
{
leap->left->imageData[j+i*frame->width] = data[j*2+i*frame->width*2];
leap->right->imageData[j+i*frame->width] = data[j*2+1+i*frame->width*2];
}
}
}

//process(leap);

pthread_mutex_unlock(&leap->lock);

leap->count++;
}

static int _leap_init(leap_t *leap)
{
uint16_t saturation;
uint16_t x;

uvc_device_handle_t *devh = leap->devh;

uvc_set_white_balance_temperature(devh, 0x7f);

for(x=0x00;x<=0x0d;x++)
uvc_set_sharpness(devh, x);
for(x=0x64;x<=0xff;x++)
uvc_set_sharpness(devh, x);

uvc_set_sharpness(devh, 0x62);
uvc_set_sharpness(devh, 0x63);

uvc_set_sharpness(devh, 0x10);
uvc_set_saturation(devh, 0x6e);
uvc_set_sharpness(devh, 0x11);
uvc_set_saturation(devh, 0x31);
uvc_set_sharpness(devh, 0x12);
uvc_set_saturation(devh, 0x0c);
uvc_set_sharpness(devh, 0x13);
uvc_set_saturation(devh, 0xfa);
uvc_set_sharpness(devh, 0x2c);
uvc_set_saturation(devh, 0x2a);
uvc_set_sharpness(devh, 0x2d);
uvc_set_saturation(devh, 0x79);
uvc_set_sharpness(devh, 0x2e);
uvc_set_saturation(devh, 0x17);
uvc_set_sharpness(devh, 0x2f);
uvc_set_saturation(devh, 0x8b);
uvc_set_sharpness(devh, 0x14);

for(x=0x15;x<=0x20;x++)
uvc_set_sharpness(devh, x);

uvc_set_saturation(devh, 0x1f);
uvc_set_sharpness(devh, 0x21);
uvc_set_saturation(devh, 0x12);
uvc_set_sharpness(devh, 0x22);
uvc_set_saturation(devh, 0x8c);
uvc_set_sharpness(devh, 0x23);
uvc_set_saturation(devh, 0x4d);
uvc_set_sharpness(devh, 0x24);
uvc_set_saturation(devh, 0xcc);
uvc_set_sharpness(devh, 0x25);
uvc_set_saturation(devh, 0xe1);
uvc_set_sharpness(devh, 0x26);
uvc_set_saturation(devh, 0x8d);
uvc_set_sharpness(devh, 0x27);

uvc_set_saturation(devh, 0x92);
uvc_set_sharpness(devh, 0x62);

uvc_set_sharpness(devh, 0x63);

uvc_set_focus_abs(devh, 0x03e8);
uvc_set_contrast(devh, 0x01);
uvc_set_brightness(devh, 0x04);
uvc_set_focus_abs(devh, 0x03e8);
uvc_set_zoom_abs(devh, 0xc8);
uvc_set_gain(devh, 0x10);
uvc_set_gamma(devh, 0x01);
uvc_set_contrast(devh, 0x00);
uvc_set_contrast(devh, 0x42);
uvc_set_contrast(devh, 0x43);
uvc_set_contrast(devh, 0x44);
uvc_set_contrast(devh, 0x06);
uvc_set_contrast(devh, 0x3c05);
uvc_set_white_balance_temperature(devh, 0x7f);

for(x=0x00;x<=0x0d;x++)
uvc_set_sharpness(devh, x);

uvc_set_sharpness(devh, 0x62);
uvc_set_sharpness(devh, 0x63);

return 0;
}

void leap_diag(leap_t *leap)
{
uvc_print_diag(leap->devh, stderr);
}

int leap_open(leap_t **leap)
{
uvc_stream_ctrl_t ctrl;
uvc_error_t res;

*leap = (leap_t *)calloc(1, sizeof(leap_t));

res = uvc_init(&(*leap)->ctx, NULL);
if (res < 0) {
uvc_perror(res, "uvc_init");
return -1;
}
res = uvc_find_device(
(*leap)->ctx, &(*leap)->dev,
0, 0, NULL); /* filter devices: vendor_id, product_id, "serial_num" */
if(res < 0)
return -1;

res = uvc_open((*leap)->dev, &(*leap)->devh);

_leap_init(*leap);

res = uvc_get_stream_ctrl_format_size((*leap)->devh, &ctrl, UVC_FRAME_FORMAT_ANY, 640, 480, 57);

res = uvc_start_streaming((*leap)->devh, &ctrl, cb, (void *)*leap, 0);

return 0;
}

int leap_close(leap_t *leap)
{
uvc_close(leap->devh);
uvc_unref_device(leap->dev);
uvc_exit(leap->ctx);
return 0;
}
27 changes: 27 additions & 0 deletions leap.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifndef LEAP_H_
#define LEAP_H_

#include <libuvc/libuvc.h>
#include <opencv2/core/core_c.h>

typedef struct _leap_t
{
uvc_context_t *ctx;
uvc_device_t *dev;
uvc_device_handle_t *devh;

IplImage *left;
IplImage *right;

IplImage *i;

pthread_mutex_t lock;

uint64_t count;
} leap_t;

int leap_open(leap_t **leap);
int leap_close(leap_t *leap);
void leap_diag(leap_t *leap);

#endif
10 changes: 10 additions & 0 deletions leap_calibrate.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <stdio.h>
#include <stdlib.h>

#include <opencv2/core/core_c.h>

int leap_calibrate_frame()
{

return 0;
}
Binary file added libuvc.dylib
Binary file not shown.
Loading

0 comments on commit fbfc732

Please sign in to comment.