-//版本二 可以识别手势,能使用
#include <assert.h>
#include <fcntl.h>
#include <pthread.h>
#include <errno.h>
#include "device.h"
-#include "mg_log.h"
+#include "mg_log.h"
#include "als.h"
#include "led.h"
#include "gesture.h"
#include "rkmedia_api.h"
-
-static als_info_t * gr_info;
static int32_t stop = 0;
static bool quit = false;
static uint32_t camera_id;
-static const STDetectResult *mg_detectResult = NULL;
-
-
-#define SENSTIME_AI_TEST /*senstime test*/
-#define IMAGE_CAPTURE_TEST /*capture test*/
-#define ST_AI_IMAGE_W 1280 //1920
-#define ST_AI_IMAGE_H 720 //1080
-#define GR_PALM 4096 //手掌
+static uint32_t my_privacy = 0;
+static const STDetectResult *mg_detectResult = NULL;
+#define ST_AI_IMAGE_W 1280 // 1920
+#define ST_AI_IMAGE_H 720 // 1080
static STResult addModels(STHandle handle, int mode)
return ret;
}
-STHandle g_SThandle=NULL;
+STHandle g_SThandle = NULL;
static int sentime_ai_init(void)
{
- STResult ret = ST_OK;
- ret = STAsteriaSetI2CBusNumber(5);
- ST_CHECK_RET("set i2c bus number");
- ret = STAsteriaAddLicense("/usr/share/st_model/license.lic");
- ST_CHECK_RET("add license");
- ret = STAsteriaCreate(&g_SThandle);
- ST_CHECK_RET("create handle");
- ret = addModels(g_SThandle, ST_DETECT_MODE_VIDEO);
- ST_CHECK_RET_DESTROY_HANDLE("add models");
- ret = STAsteriaInitialize(g_SThandle, ST_DETECT_MODE_VIDEO);
- ST_CHECK_RET_DESTROY_HANDLE("init")
- STAsteriaSetDetection(g_SThandle, ST_DETECT_MODE_VIDEO, ST_DETECT_FACE|ST_DETECT_FACE_EYEBROW|ST_DETECT_FACE_EYELID|ST_DETECT_FACE_LIP|ST_DETECT_FACE_DISTANCE| ST_DETECT_FACE_ATTRIBUTE |ST_DETECT_FACE_FEATURE|ST_DETECT_HAND|ST_DETECT_BODY|ST_DETECT_MOTION);
- printf("STAsteriaInitialize success\n");
- return 0;
+ STResult ret = ST_OK;
+ ret = STAsteriaSetI2CBusNumber(5);
+ ST_CHECK_RET("set i2c bus number");
+ ret = STAsteriaAddLicense("/usr/share/st_model/license.lic");
+ ST_CHECK_RET("add license");
+ ret = STAsteriaCreate(&g_SThandle);
+ ST_CHECK_RET("create handle");
+ ret = addModels(g_SThandle, ST_DETECT_MODE_VIDEO);
+ ST_CHECK_RET_DESTROY_HANDLE("add models");
+ ret = STAsteriaInitialize(g_SThandle, ST_DETECT_MODE_VIDEO);
+ ST_CHECK_RET_DESTROY_HANDLE("init")
+ STAsteriaSetDetection(g_SThandle, ST_DETECT_MODE_VIDEO, ST_DETECT_FACE | ST_DETECT_FACE_EYEBROW | ST_DETECT_FACE_EYELID | ST_DETECT_FACE_LIP | ST_DETECT_FACE_DISTANCE | ST_DETECT_FACE_ATTRIBUTE | ST_DETECT_FACE_FEATURE | ST_DETECT_HAND | ST_DETECT_BODY | ST_DETECT_MOTION);
+ printf("STAsteriaInitialize success\n");
+ return 0;
}
static int sentime_ai_deinit(void)
{
- if(g_SThandle!=NULL)
- STAsteriaDestroy(g_SThandle);
+ if (g_SThandle != NULL)
+ STAsteriaDestroy(g_SThandle);
- g_SThandle=NULL;
+ g_SThandle = NULL;
return 0;
}
-
-static void sigterm_handler(int sig) {
- fprintf(stderr, "signal %d\n", sig);
- quit = true;
+static void sigterm_handler(int sig)
+{
+ fprintf(stderr, "signal %d\n", sig);
+ quit = true;
}
-int rk_isp_init(char index,char *iq_dir)
+int rk_isp_init(char index, char *iq_dir)
{
- int ret=0;
- printf("iq_dir %s ====\n",iq_dir);
+ int ret = 0;
+ printf("iq_dir %s ====\n", iq_dir);
#ifdef RKAIQ
- ret = SAMPLE_COMM_ISP_Init(index, RK_AIQ_WORKING_MODE_NORMAL, RK_TRUE, iq_dir);
- if (ret)
- return -1;
-
- SAMPLE_COMM_ISP_Run(index);
-
+ ret = SAMPLE_COMM_ISP_Init(index, RK_AIQ_WORKING_MODE_NORMAL, RK_TRUE, iq_dir);
+ if (ret)
+ return -1;
+
+ SAMPLE_COMM_ISP_Run(index);
+
#endif
- return ret;
+ return ret;
}
-
void rk_isp_deinit(char index)
{
#ifdef RKAIQ
- SAMPLE_COMM_ISP_Stop(index);
+ SAMPLE_COMM_ISP_Stop(index);
#endif
}
-void rk_vi_init(VI_PIPE ViPipe, VI_CHN ViChn,uint32_t video_width,uint32_t video_height)
+void rk_vi_init(VI_PIPE ViPipe, VI_CHN ViChn, uint32_t video_width, uint32_t video_height)
{
- VI_CHN_ATTR_S vi_chn_attr;
- int ret=0;
- memset(&vi_chn_attr, 0, sizeof(vi_chn_attr));
- vi_chn_attr.pcVideoNode = "rkispp_scale0";
- vi_chn_attr.u32BufCnt = 5;
- vi_chn_attr.u32Width = video_width;
- vi_chn_attr.u32Height = video_height;
- vi_chn_attr.enPixFmt = IMAGE_TYPE_NV12;
- vi_chn_attr.enWorkMode = VI_WORK_MODE_NORMAL;
- //vi_chn_attr.enBufType=VI_CHN_BUF_TYPE_MMAP;
- ret = RK_MPI_VI_SetChnAttr(ViPipe, ViChn, &vi_chn_attr);
- ret |= RK_MPI_VI_EnableChn(ViPipe, ViChn);
- if (ret) {
- printf("Create vi[%d] failed! ret=%d\n",ViPipe, ret);
- return;
- }
-
- ret = RK_MPI_VI_StartStream(ViPipe, ViChn);
- if (ret) {
- printf("RK_MPI_VI_StartStream [ViChn] failed! ret=%d\n", ret);
- return;
- }
+ VI_CHN_ATTR_S vi_chn_attr;
+ int ret = 0;
+
+
+ memset(&vi_chn_attr, 0, sizeof(vi_chn_attr));
+ vi_chn_attr.pcVideoNode = "rkispp_scale0";
+ vi_chn_attr.u32BufCnt = 5;
+ vi_chn_attr.u32Width = video_width;
+ vi_chn_attr.u32Height = video_height;
+ vi_chn_attr.enPixFmt = IMAGE_TYPE_NV12;
+ vi_chn_attr.enWorkMode = VI_WORK_MODE_NORMAL;
+ // vi_chn_attr.enBufType=VI_CHN_BUF_TYPE_MMAP;
+
+ ret = RK_MPI_VI_SetChnAttr(ViPipe, ViChn, &vi_chn_attr);
+ ret |= RK_MPI_VI_EnableChn(ViPipe, ViChn);
+ if (ret)
+ {
+ printf("Create vi[%d] failed! ret=%d\n", ViPipe, ret);
+ return;
+ }
+ ret = RK_MPI_VI_StartStream(ViPipe, ViChn);
+ if (ret)
+ {
+ printf("RK_MPI_VI_StartStream [ViChn] failed! ret=%d\n", ret);
+ return;
+ }
}
-
-int rk_vi_setfps( VI_CHN ViChn,int fps)
+int rk_vi_setfps(VI_CHN ViChn, int fps)
{
- int ret;
- MPP_FPS_ATTR_S fps_attr;
-
- fps_attr.s32FpsInDen=1;
- fps_attr.s32FpsInNum=30;
- fps_attr.s32FpsOutDen=1;
- fps_attr.s32FpsOutNum=fps;
- ret=RK_MPI_SYS_SetFrameRate(RK_ID_VI,ViChn,&fps_attr);
- if (ret) {
- printf("RK_MPI_SYS_SetFrameRate [%d] failed! ret=%d\n",ViChn, ret);
- return -1;
- }
- return 0;
+ int ret;
+ MPP_FPS_ATTR_S fps_attr;
+
+ fps_attr.s32FpsInDen = 1;
+ fps_attr.s32FpsInNum = 30;
+ fps_attr.s32FpsOutDen = 1;
+ fps_attr.s32FpsOutNum = fps;
+ ret = RK_MPI_SYS_SetFrameRate(RK_ID_VI, ViChn, &fps_attr);
+ if (ret)
+ {
+ printf("RK_MPI_SYS_SetFrameRate [%d] failed! ret=%d\n", ViChn, ret);
+ return -1;
+ }
+ return 0;
}
-
-
-//关闭光圈
static void gr_ring_disable(light_ctrl_t led_ctrl)
{
ring_led_off(led_ctrl, 0, 0, 1);
}
-//光圈闪烁和呼吸
static void gr_ring_enable(light_ctrl_t led_ctrl)
{
ring_led_flash(led_ctrl, 1000, 5000);
ring_led_breath(led_ctrl, 2000, 0);
}
-
-
-//Report data and turn off gesture mode
+// Report data and turn off gesture mode
static int32_t reportdp_and_close_ring_gr(light_ctrl_t led_ctrl)
{
printf("zf 关闭手势,上报手掌\n");
- gr_ring_disable(led_ctrl); //关闭灯光
- dp_recognition_running_report(0); //上报手势开关
+ gr_ring_disable(led_ctrl);
+ dp_recognition_running_report(0);
+ sleep(1);
}
-
-//判断白天还是黑夜
-static void gr_als_t(gr_ctrl_t* gr_ctrl)
+// 修改:状态发生变化时再切换摄像头
+static uint32_t last_als_status = -1;
+static int32_t gr_als_t(gr_ctrl_t *gr_ctrl)
{
+ als_info_t *gr_info;
- if(!gr_info){
- printf( "malloc als_info failed \n");
- return;
+ if (gr_ctrl == NULL)
+ {
+ printf(" gr_ctrl == NULL \n");
+ goto error;
}
- mg_als_read(gr_ctrl->als_ctrl,gr_info);
-
- if(gr_info->status == BRIGHT){
- ir_led_off(gr_ctrl->light_ctrl); //禁用红外补光
- camera_id = 1;
- }else if(gr_info->status == DARK){
- ir_led_on(gr_ctrl->light_ctrl, 100); //开启红外补光
- camera_id = 0;
+
+ if (cfg_privacy_mode_read(gr_ctrl->dev) == 0)
+ {
+ gr_info = mg_als_read(gr_ctrl->als_ctrl);
+ if(gr_info != NULL){
+ if (last_als_status != gr_info->status)
+ {
+ last_als_status = gr_info->status;
+ if (last_als_status == BRIGHT)
+ {
+ ir_led_off(gr_ctrl->light_ctrl); // 禁用红外补光
+ camera_id = 1;
+ printf("开启rgb,禁止ir\n");
+ }
+ else if (last_als_status == DARK)
+ {
+ ir_led_on(gr_ctrl->light_ctrl, 100); // 开启红外补光
+ camera_id = 0;
+ printf("开启ir,关闭rgb\n");
+ }
+ }
+ gr_info = NULL;
+ }
}
+error:
+ return -1;
}
-
-
-
-//zf 判断是否开启或者关闭手势识别
-//算法识别
static int32_t gr_read_gesture(void)
{
int32_t ret = -1;
- if(!mg_detectResult)
+ if (mg_detectResult == NULL)
goto error;
- if(mg_detectResult->handCount){
- switch(mg_detectResult->hands[0].action){
- case ST_HAND_ACTION_SHOOT:
- ret = GS_GUN;
- break;
- case ST_HAND_ACTION_LITTLE_FINGER:
- ret = GS_LITTLE_FINGER;
- break;
- case ST_HAND_ACTION_ROCK_ON:
- ret = GS_HORNED_HAND;
- break;
- case ST_HAND_ACTION_I_LOVE_YOU:
- ret = GS_ILOVEYOU;
- break;
- case ST_HAND_ACTION_FOUR:
- ret = GS_FOUR_FINGERS;
- break;
- case ST_HAND_ACTION_THREE:
- ret = GS_THREE_FINGERS;
- break;
- case ST_HAND_ACTION_OK:
- ret = GS_OK;
- break;
- case ST_HAND_ACTION_THUMBS_UP:
- ret = GS_THUMBS_UP;
- break;
- case ST_HAND_ACTION_V:
- ret = GS_SCISSORS;
- break;
- case ST_HAND_ACTION_PALM:
- ret = GR_PALM;
- break;
- default:
- ret = -1;
- break;
- }
- mg_detectResult = NULL; //清空是为了避免下次读取的是上一次的值
- printf("gesrtue action ===================== %d\n",ret);
+ if (mg_detectResult->handCount)
+ {
+ switch (mg_detectResult->hands[0].action)
+ {
+ case ST_HAND_ACTION_SHOOT:
+ ret = GS_GUN;
+ break;
+ case ST_HAND_ACTION_LITTLE_FINGER:
+ ret = GS_LITTLE_FINGER;
+ break;
+ case ST_HAND_ACTION_ROCK_ON:
+ ret = GS_HORNED_HAND;
+ break;
+ case ST_HAND_ACTION_I_LOVE_YOU:
+ ret = GS_ILOVEYOU;
+ break;
+ case ST_HAND_ACTION_FOUR:
+ ret = GS_FOUR_FINGERS;
+ break;
+ case ST_HAND_ACTION_THREE:
+ ret = GS_THREE_FINGERS;
+ break;
+ case ST_HAND_ACTION_SIX:
+ ret = GS_WELL_PLAYED;
+ break;
+ case ST_HAND_ACTION_INDEX_FINGER:
+ ret = GS_FINGERTIP;
+ break;
+ case ST_HAND_ACTION_FINGER_HEART:
+ ret = GS_FINGER_HEART;
+ break;
+ case ST_HAND_ACTION_FIST:
+ ret = GS_ROCK;
+ break;
+ case ST_HAND_ACTION_PALM:
+ ret = GS_PAPER;
+ break;
+ case ST_HAND_ACTION_THUMBS_UP:
+ ret = GS_THUMBS_UP;
+ break;
+ case ST_HAND_ACTION_V:
+ ret = GS_SCISSORS;
+ break;
+ case ST_HAND_ACTION_OK:
+ ret = GS_OK;
+ break;
+ default:
+ ret = -1;
+ break;
+ }
+ mg_detectResult = NULL;
+ printf("gesrtue action zzzzzzzzzzzzzzzzzzzzzz %d\n", ret);
return ret;
- }
+ }
error:
- return -1;
+ return -2;
}
-
-//zf
-//检测有效手势,1s之内如果不是手掌就返回-1,否则返回0
+static bool escalation = 1;
+static int32_t repeating_gestures = -10;
+static int32_t timeout = 0;
static int32_t gr_detect_effective(gesture_ev_t ev)
{
- sleep(1);
- if(gr_read_gesture() == ev){
- if(ev != GR_PALM){
- dp_gesture_event_report(ev);
- printf("上报dp ===================== %d\n",ev);
- }
- return 0;
+ usleep(200 * 1000);
+
+ if (time(NULL) - timeout > 30)
+ {
+ escalation = 1;
+ }
+
+ if (gr_read_gesture() == ev)
+ {
+ if ((repeating_gestures != ev) || (escalation == 1))
+ {
+ dp_gesture_event_report(ev);
+ timeout = time(NULL);
+ escalation = 0;
+ printf("上报dp ===================== %d\n", ev);
+ }
+ else
+ {
+ printf("不上报 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx %d\n", ev);
+ }
+ repeating_gestures = ev;
+ return 0;
}
return -1;
}
-
-//检测是否是手掌,1s之内如果不是手掌就返回-1,否则返回0
static int32_t gr_ai_detect_palm(void)
{
- if(gr_detect_effective(GR_PALM) == 0){
- return 0;
+ usleep(800*1000);
+ if (gr_read_gesture() == GS_PAPER)
+ {
+ return 0;
}
+ printf("手掌未保持1s \n");
return -1;
}
-//zf
-void* gr_task( void* param )
+void *gr_task(void *param)
{
int ret;
- uint32_t init = 1;
+ //uint32_t init = 1;
uint32_t dp_timeout, gr_time;
uint32_t time_flasg;
- gr_ctrl_t *p_gr = ( gr_ctrl_t*)param;
+ gr_ctrl_t *p_gr = (gr_ctrl_t *)param;
+ gr_time = time(NULL);
- gr_time = time(NULL);
+ while (!stop)
+ {
+ usleep(100 * 1000);
- while(!stop){
+ my_privacy = cfg_privacy_mode_read(p_gr->dev);
+ if (my_privacy == 1)
+ {
+ usleep(100 * 1000);
+ continue;
+ }
- usleep(1000);
- dp_timeout = cfg_recognition_duration_read( p_gr->dev);
- if(init)
- gr_als_t(p_gr);
+ dp_timeout = cfg_recognition_duration_read(p_gr->dev);
+ if (my_privacy == 0)
+ {
+ gr_als_t(p_gr);
+ }
- time_flasg = 1;//更新时间
- if(gr_read_gesture() == GR_PALM){
- if(gr_ai_detect_palm() == 0){
- printf("开启手势模式\n");
- dp_recognition_running_report(1);
- gr_ring_enable(p_gr->light_ctrl);
- sleep(1);
- while(!stop){
- usleep(100*000);
- if(time_flasg){
+ time_flasg = 1;
+ if (gr_read_gesture() == GS_PAPER)
+ {
+ if (gr_ai_detect_palm() == 0)
+ {
+ printf("Enable gesture mode\n");
+ dp_recognition_running_report(1);
+ gr_ring_enable(p_gr->light_ctrl);
+ while (!stop)
+ {
+ usleep(100 * 000);
+ if (time_flasg)
+ {
gr_time = time(NULL);
time_flasg = 0;
}
-
- dp_timeout = cfg_recognition_duration_read( p_gr->dev);
- if(time(NULL) - gr_time > dp_timeout){
- printf("超时退出\n");
+ dp_timeout = cfg_recognition_duration_read(p_gr->dev);
+ if (time(NULL) - gr_time > dp_timeout)
+ {
+ printf("gesture Time out\n");
reportdp_and_close_ring_gr(p_gr->light_ctrl);
- sleep(1);
break;
}
-
- gr_als_t(p_gr);
+ gr_als_t(p_gr);
ret = gr_read_gesture();
- if( ret == -1 ){
+ if (ret < 0)
+ {
+ if (ret == -1)
+ {
+ escalation = 1;
+ }
continue;
- }else if(ret == GR_PALM){
- if(gr_ai_detect_palm() == 0){
- printf("关闭手势模式,退出\n");
- reportdp_and_close_ring_gr(p_gr->light_ctrl);
- init = 1;
- sleep(1);
- break;
+ }
+ else if (ret == GS_PAPER)
+ {
+ if (gr_ai_detect_palm() == 0)
+ {
+ printf("Turn off gesture mode\n");
+ reportdp_and_close_ring_gr(p_gr->light_ctrl);
+ break;
}
- }else{
- gr_detect_effective(ret);
- time_flasg = 1;
+ }
+ else
+ {
+ gr_detect_effective(ret);
+ time_flasg = 1;
}
}
- }else{
- init = 0;
- continue;
}
}
- }
+ }
return NULL;
}
-static void* ai_detect(void *arg)
+static void *ai_detect(void *arg)
{
- struct timespec ts;
- MEDIA_BUFFER mb = NULL;
+
int ret;
-#if 0
- time_t now = 0;
- time_t time_2023 = 0;
- struct tm tm_2023;
-
- tm_2023.tm_sec = 0;
- tm_2023.tm_min = 0;
- tm_2023.tm_hour = 0;
- tm_2023.tm_mday = 1;
- tm_2023.tm_mon = 6;
- tm_2023.tm_year = 123;
- tm_2023.tm_wday = 0;
- tm_2023.tm_yday = 1;
- tm_2023.tm_isdst= 0;
-
- time_2023 = mktime( &tm_2023 );
- while( 1 ){
- //等待网络时间获取,避免license报错
- now = time( NULL );
- if( now > time_2023 ){
- printf( "------------------wait ntp update, to now [%ld] > [%ld] ......\n",now, time_2023 );
- break;
- }
- sleep(1);
- printf( "wait ntp update, to now [%ld] > [%ld] ......\n",now, time_2023 );
- }
-#endif
+ int privacy = 0;
+ MEDIA_BUFFER mb = NULL;
retry_for_wait_ntp:
- ret=sentime_ai_init();
- if(ret==-15){
- printf( "sentime_ai_init fail -15, retry...\n" );
- sleep(2);
- goto retry_for_wait_ntp;
+ ret = sentime_ai_init();
+ if (ret == -15)
+ {
+ printf("sentime_ai_init fail -15, retry...\n");
+ sleep(2);
+ goto retry_for_wait_ntp;
}
- if(ret!=0)
+ if (ret != 0)
{
printf("sentime_ai_init fail! ret=%d\n", ret);
return NULL;
}
- int nv12_buffer_size = ST_AI_IMAGE_W *ST_AI_IMAGE_H * 3/2; // nv12 3/2, rgb 3
+ int nv12_buffer_size = ST_AI_IMAGE_W * ST_AI_IMAGE_H * 3 / 2; // nv12 3/2, rgb 3
unsigned char *image_data = (unsigned char *)malloc(nv12_buffer_size);
- if(image_data==NULL)
+ if (image_data == NULL)
return NULL;
- STImage detectImage = {0};
+ STImage detectImage = {0};
detectImage.data = image_data;
detectImage.format = ST_PIXEL_FORMAT_NV12;
detectImage.width = ST_AI_IMAGE_W;
- detectImage.height = ST_AI_IMAGE_H;
+ detectImage.height = ST_AI_IMAGE_H;
+ //const STDetectResult *detectResult = NULL;
- while (!quit) {
-
- //mb = RK_MPI_SYS_GetMediaBuffer(RK_ID_VI, camera_id, -1);
- mb = RK_MPI_SYS_GetMediaBuffer(RK_ID_VI, 0, -1);
- if (!mb) {
- usleep(100*1000);
- continue;
+ while (!quit)
+ {
+ usleep(100 * 1000);
+ if (my_privacy == 0)
+ {
+ if (privacy)
+ {
+ privacy = 0;
+ printf("===============Exit privacy mode================\n");
+ }
+ mb = RK_MPI_SYS_GetMediaBuffer(RK_ID_VI, camera_id, -1);
+ if (!mb)
+ {
+ usleep(100 * 1000);
+ continue;
+ }
+ else
+ {
+ memcpy(image_data, RK_MPI_MB_GetPtr(mb), nv12_buffer_size);
+ RK_MPI_MB_ReleaseBuffer(mb);
+ STAsteriaDetect(g_SThandle, ST_DETECT_MODE_VIDEO, &detectImage, &mg_detectResult);
+ }
}
- else
+ else if (my_privacy == 1)
{
- memcpy(image_data,RK_MPI_MB_GetPtr(mb),nv12_buffer_size);
- RK_MPI_MB_ReleaseBuffer(mb);
- STAsteriaDetect(g_SThandle, ST_DETECT_MODE_VIDEO, &detectImage, &mg_detectResult);
- usleep(100*1000);
+ if (!privacy)
+ {
+ privacy = 1;
+ printf("================== Go to privacy mode ===================\n");
+ }
}
}
-
if (image_data)
- free(image_data);
-
+ free(image_data);
+
sentime_ai_deinit();
- return NULL;
+ return NULL;
}
-int gr_register(gr_ctrl_t* gr_ctrl, uint32_t threshold_high, uint32_t threshold_low)
-{
- int ret;
-
- pthread_t th2;
- pthread_t gr_thread;
-
- gr_info = (als_info_t *)malloc(sizeof(gr_info));
+int gr_register(gr_ctrl_t *gr_ctrl, uint32_t threshold_high, uint32_t threshold_low)
+{
+ int ret;
+ pthread_t th2;
+ pthread_t gr_thread;
gr_ctrl->als_ctrl = mg_als_open();
- if(gr_ctrl->als_ctrl == NULL){
+ if (gr_ctrl->als_ctrl == NULL)
+ {
printf("als open failed \n");
goto app_ext1;
}
- mg_als_cfg(gr_ctrl->als_ctrl,threshold_high,threshold_low);
+ mg_als_cfg(gr_ctrl->als_ctrl, threshold_high, threshold_low);
- ret = rk_isp_init(0,"/etc/iqfiles/");
- if( ret < 0 ){
- printf("rk_isp_init failed!\n");
- goto app_ext1;
- }
- //rk_isp_init(1,"/etc/iqfiles/");
+ ret = rk_isp_init(0, "/etc/iqfiles/");
+ if (ret < 0)
+ {
+ printf("rk_isp_init failed!\n");
+ goto app_ext1;
+ }
- RK_MPI_SYS_Init();
- rk_vi_init(0,0,ST_AI_IMAGE_W,ST_AI_IMAGE_H);
- //rk_vi_init(1,1,ST_AI_IMAGE_W,ST_AI_IMAGE_H);
- rk_vi_setfps(0,15);
- //rk_vi_setfps(1,15);
+ ret = rk_isp_init(1, "/etc/iqfiles/");
+ if (ret < 0)
+ {
+ printf("rk_isp_init failed!\n");
+ goto app_ext1;
+ }
- usleep(100*1000);
+ RK_MPI_SYS_Init();
+ rk_vi_init(0, 0, ST_AI_IMAGE_W, ST_AI_IMAGE_H);
+ rk_vi_setfps(0, 15);
+ rk_vi_init(1,1,ST_AI_IMAGE_W,ST_AI_IMAGE_H);
+ rk_vi_setfps(1,15);
- if (pthread_create(&th2, NULL, ai_detect, NULL)) {
- printf("create GetBuffer thread failed!\n");
- quit=1;
- goto app_ext1;
- }
+ usleep(100 * 1000);
- if( pthread_create( &gr_thread, NULL, gr_task, gr_ctrl) != 0 ){
- printf("create hand_ic failed!");
- goto app_ext1;
- }
- return 0;
+ if (pthread_create(&th2, NULL, ai_detect,NULL))
+ {
+ printf("create GetBuffer thread failed!\n");
+ quit = 1;
+ goto app_ext1;
+ }
-app_ext1:
- RK_MPI_VI_DisableChn(0, 0);
- //RK_MPI_VI_DisableChn(1, 1);
- rk_isp_deinit(0);
- //rk_isp_deinit(1);
- return -1;
-}
+ if (pthread_create(&gr_thread, NULL, gr_task, gr_ctrl) != 0)
+ {
+ printf("create hand_ic failed!");
+ goto app_ext1;
+ }
+ return 0;
+app_ext1:
+ RK_MPI_VI_DisableChn(0, 0);
+ RK_MPI_VI_DisableChn(1, 1);
+ rk_isp_deinit(0);
+ rk_isp_deinit(1);
+ return -1;
+}
-void gr_close(gr_ctrl_t* gr_ctrl)
+void gr_close(gr_ctrl_t * gr_ctrl)
{
stop = 1;
- usleep(100*1000);
+ usleep(100 * 1000);
- if(gr_ctrl){
+ if (gr_ctrl)
+ {
quit = 1;
- usleep(100*1000);
- RK_MPI_VI_DisableChn(0, 0);
- //RK_MPI_VI_DisableChn(1, 1);
- rk_isp_deinit(0);
- //rk_isp_deinit(1);
+ usleep(100 * 1000);
+ RK_MPI_VI_DisableChn(0, 0);
+ RK_MPI_VI_DisableChn(1, 1);
+ rk_isp_deinit(0);
+ rk_isp_deinit(1);
- mg_als_close(gr_ctrl->als_ctrl);
- free(gr_info);
- gr_info = NULL;
+ mg_als_close(gr_ctrl->als_ctrl);
- MG_LOGD( "tw8013 gr close!\n" );
+ MG_LOGD("tw8013 gr close!\n");
}
}
-
-
-
-
-//测试程序
-// int main(int argc, char *argv[])
-// {
-// int ret;
-
-// gr_ctrl_t *test = (gr_ctrl_t *)malloc(sizeof(gr_ctrl_t));
-
-// light_ctrl_t ctrl = mg_led_open();
-// if (!ctrl)
-// {
-// printf("led test..., open led failed\n");
-// goto app_ext1;
-// }
-// printf("led test..., open led, ret:%p\n", ctrl);
-// test->light_ctrl = ctrl;
-
-// printf("zzzzz\n");
-
-// signal(SIGINT, sigterm_handler);
-// usleep(100 * 1000);
-
-// ret = gr_register(test, 1000, 400);
-
-// if (ret)
-// {
-// printf("gr_register falied === \n");
-// }
-
-// // sleep(15);
-// // gr_close(test);
-
-// while (!quit)
-// {
-// usleep(100 * 1000);
-// }
-
-// app_ext1:
-// free(test);
-// test = NULL;
-// return -1;
-// }
-
#if 0
static gr_ctrl_t gr_ctrl;
gr_ctrl.light_ctrl = g_led_ctrl;
gr_ctrl.dev = &g_mg_dev;
- load_als_threshold( &als_th_high, &als_th_low );
+ //load_als_threshold( &als_th_high, &als_th_low );
signal(SIGINT, sigterm_handler);
usleep(100 * 1000);
return ret;
}
-#endif
+
+#else
static gr_ctrl_t gr_ctrl;
-extern light_ctrl_t g_led_ctrl;
+extern light_ctrl_t g_led_ctrl;
extern mg_dev_t g_mg_dev;
-int32_t gesture_recognition_start( void )
+int32_t gesture_recognition_start(void)
{
- int32_t ret = 0;
- uint32_t als_th_high = 1000;
- uint32_t als_th_low = 400;
-
- memset( &gr_ctrl, 0, sizeof( gr_ctrl ) );
+ int32_t ret = 0;
+ uint32_t als_th_high;
+ uint32_t als_th_low;
- //zf
- // g_led_ctrl = mg_led_open();
- // if (!g_led_ctrl)
- // {
- // printf("led test..., open led failed\n");
- // return -1;
- // }
- //zf_end
+ memset(&gr_ctrl, 0, sizeof(gr_ctrl));
- gr_ctrl.light_ctrl = g_led_ctrl;
- gr_ctrl.dev = &g_mg_dev;
- load_als_threshold( &als_th_high, &als_th_low );
+ gr_ctrl.light_ctrl = g_led_ctrl;
+ gr_ctrl.dev = &g_mg_dev;
+ load_als_threshold(&als_th_high, &als_th_low);
- // signal(SIGINT, sigterm_handler);
- usleep(100 * 1000);
+ usleep(100 * 1000);
- //printf("als_th_high = %d als_th_low = %d\n",als_th_high,als_th_low);
- ret = gr_register( &gr_ctrl, als_th_high, als_th_low );
+ ret = gr_register(&gr_ctrl, als_th_high, als_th_low);
- if (ret){
- MG_LOGE("gr_register falied === \n");
- ret = -1;
- }
+ if (ret)
+ {
+ MG_LOGE("gr_register falied === \n");
+ ret = -1;
+ }
- return ret;
+ return ret;
}
+#endif
+