Skip to content

Commit

Permalink
Orbbec: Support color channel for Stereo/Embedded S and supress warni…
Browse files Browse the repository at this point in the history
…ngs we can not avoid.
  • Loading branch information
sisiplac committed Sep 2, 2019
1 parent b89a620 commit c739bb5
Show file tree
Hide file tree
Showing 9 changed files with 1,551 additions and 68 deletions.
30 changes: 30 additions & 0 deletions BetaCameras/OrbbecOpenNI/AutoResetEvent.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "AutoResetEvent.h"
#include <mutex>
#include <condition_variable>
#include <thread>

bool flag_ = false;
std::mutex protect_;
std::condition_variable signal_;

void AutoResetEventSet()
{
std::lock_guard<std::mutex> _(protect_);
flag_ = true;
signal_.notify_one();
}

void AutoResetEventReset()
{
std::lock_guard<std::mutex> _(protect_);
flag_ = false;
}

bool AutoResetEventWaitOne()
{
std::unique_lock<std::mutex> lk(protect_);
while (!flag_) // prevent spurious wakeups from doing harm
signal_.wait(lk);
flag_ = false; // waiting resets the flag
return true;
}
8 changes: 8 additions & 0 deletions BetaCameras/OrbbecOpenNI/AutoResetEvent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

#include <stdio.h>

void AutoResetEventSet();
void AutoResetEventReset();
bool AutoResetEventWaitOne();

13 changes: 13 additions & 0 deletions BetaCameras/OrbbecOpenNI/ObCommon.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef __OB_COMMON_H__
#define __OB_COMMON_H__


//#include <XnStatus.h>
#include <iostream>


#define OB_LOG_INFO(args) printf("OB_INFO : ");printf(args)
#define OB_LOG_ERROR(args) printf("OB_ERROR : ");printf(args)


#endif // __OB_COMMON_H__
55 changes: 55 additions & 0 deletions BetaCameras/OrbbecOpenNI/ObUvcAPI.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#ifndef __OB_UVCAPI_H__
#define __OB_UVCAPI_H__


#include <OniCTypes.h>
#include <stdint.h>

#include <vector>
#include <map>
#include <memory>
#include <functional>
#include <string>

#include "AutoResetEvent.h"

//To keep things simple, we should take the highest color resolution which matches the aspect ratio of the intrinsics and
//has maximum FPS (in our case 30)

//With this mode we can get up to 50fps, but depending on the illumination it can drop down to 15fps
//#define UVC_COLOR_WIDTH 1280
//#define UVC_COLOR_HEIGHT 960

//With this mode we can get up to 26fps, but depending on the illumination it can drop down to 15fps
//#define UVC_COLOR_WIDTH 2592
//#define UVC_COLOR_HEIGHT 1944

#define UVC_COLOR_MEDIASUBTYPE MEDIASUBTYPE_NV12
//#define UVC_COLOR_MEDIASUBTYPE MEDIASUBTYPE_MJPG //Also works, but needs more processing time
//#define UVC_COLOR_MEDIASUBTYPE MEDIASUBTYPE_YUY2 //Delivers high framerates only for 640x480 or lower

struct ObUVCDevice;

void ProcessorCallback(const void *frame, int size, void *pstream);

int ObUVCInit(int uvcColorWidth, int uvcColorHeight, bool uvcColorFlipImage);
void ObUVCFillColorImage(unsigned char* colorData);
void ObUVCShutdown();
void ObUVCWaitForNewColorImage();
void ConvertNV12ToRGBImage(unsigned char* nv12_image);
void ConvertYUY2ToRGBImage(unsigned char* yuy2_image);
void ConvertNV12ToRGBImageAndFlip(unsigned char* nv12_image);
void ConvertYUY2ToRGBImageAndFlip(unsigned char* yuy2_image);

int enumerate_all_devices(std::map<std::string, std::shared_ptr<ObUVCDevice>> &devices);
int get_vendor_id(const ObUVCDevice & device);
int get_product_id(const ObUVCDevice & device);

void set_stream(ObUVCDevice & device, int subdevice_index, void * pstream);

typedef std::function<void(const void * frame, int size, void *pstream)> video_channel_callback;
void set_subdevice_mode(ObUVCDevice & device, int subdevice_index, video_channel_callback callback);

void start_streaming(ObUVCDevice & device,int subdevice_index=0);
void stop_streaming(ObUVCDevice & device, int subdevice_index=0);
#endif
Loading

0 comments on commit c739bb5

Please sign in to comment.