开启左侧

【聆思CSK6 视觉AI开发套件试用】CSK6视觉套件与Jetson ...

[复制链接]
在线会员 执手踏青 发表于 2023-3-13 13:17:35 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题
原篇文章去自极术社区取聆思科技构造的CSK6 望觉AI开辟套件举动,更多开辟板试用举动请存眷极术社区网站。作家:           
产物介绍

Jetson Nano 可为运行现代 AI 算法供给 472 GFLOPS 的计较功用。它能并交运转多个神经收集并共时处置多个下分辩率的传感器,很是适宜正在 NVR 战智能网闭范围的使用法式。Jetson Nano 可为运行现代 AI 算法供给 472 GFLOPS 的计较功用。它能并交运转多个神经收集并共时处置多个下分辩率的传感器,很是适宜正在 NVR 战智能网闭范围的使用法式。
CSK6 是聆思科技新一代的 AI 芯片 SoC 产物系列,接纳多核同构架构,散成为了安谋科技STAR-MC1处置 器,HiFi4 DSP,和聆思崭新设想的 AI 神经收集处置内乱核 NPU,算力到达 128 GOPS。多核同构的设想使芯片能以较高罪耗满意音频及图象望频的 AI 使用需要。CSK6 是聆思科技新一代的 AI 芯片 SoC 产物系列,接纳多核同构架构,散成为了 ARM Star MCU,HiFi4 DSP,和聆思崭新设想的 AI 神经收集处置内乱核 NPU,算力到达 128 GOPS。多核同构的设想使芯片能以较高罪耗满意音频及图象望频的 AI 使用需要。CSK6 是聆思科技新一代的 AI 芯片 SoC 产物系列,接纳多核同构架构,散成为了 ARM Star MCU,HiFi4 DSP,和聆思崭新设想的 AI 神经收集处置内乱核 NPU,算力到达 128 GOPS。多核同构的设想使芯片能以较高罪耗满意音频及图象望频的 AI 使用需要。
软件IO交心CSK6多达33个可活络设置的GPIO,借未来患上及体会,Jetson Nano 40pin公有 18 根取开辟套件底板电子电力曲连的足位,那是不克不及从头界说的牢固功用,比CSK6少了11个。
CSK6S很友好的供给望觉SDK示例 app_algo_hsd_sample_for_csk6头肩识别 战望觉SDK示例 app_algo_fd_sample_for_csk6 人脸识别供各人初学。
开辟初学比照

原次开辟的情况是正在ubuntu20.04的情况下截至的,正在开辟的历程十分的顺遂,不能不道那是尔用的最丝滑的开辟板之一。上脚十分的快,民网的学程也写的十分棒,随着文档一步步来完毕一般皆能完毕结果。
先收一个正在jetson nano上的心罩识别,


【聆思CSK6 望觉AI开辟套件试用】CSK6望觉套件取Jetson ...-1.jpg

帧率年夜于25分辩率是1920*1080,使用tensorrt加快的yolov5-6.1
CSK6情况拆修一键操纵,拆修完如
  1. lisa info zep
  2. Operating System - #59~20.04.1-Ubuntu SMP Thu Oct 20 15:10:22 UTC 2022, version 5.15.0-53-generic x64
  3. @listenai/lisa - 2.4.5
  4. Account - 已登录或者登录已经过时
  5. Node.js environment
  6.   Node.js - v16.14.0
  7.   npm - 8.3.1
  8.   yarn - 1.22.19
  9. Global environment
  10.   git - git version 2.25.1
  11. Plugin info
  12.   zep - 1.6.8 (latest: 1.6.8)
  13. Plugin environment
  14.   env - csk6
  15.   west - West version: v0.14.0
  16.   venv - Python 3.9.7
  17.   cmake - cmake version 3.21.4
  18.   dtc - Version: DTC 1.6.0
  19.   gperf - GNU gperf 3.1
  20.   mklfs - v1.0.0 (3640bfb)
  21.   ninja - 1.10.2
  22.   protoc - libprotoc 3.19.1
  23.   xz - xz (XZ Utils) 5.2.5
  24.   cskburn - v1.18.1 (265)
  25.   zephyr-sdk-0.14.2 - arm-zephyr-eabi-gcc (Zephyr SDK 0.14.2) 10.3.0
  26.   gcc-arm-none-eabi-10.3 - arm-none-eabi-gcc (GNU Arm Embedded Toolchain 10.3-2021.10) 10.3.1 20210824 (release)
  27.   jlink-venus - V7.58
  28.   ZEPHYR_BASE - /home/ljx/.listenai/csk-sdk/zephyr (版原: v1.1.1-alpha.2, co妹妹it: 3e15ca75)
  29.   PLUGIN_HOME - /home/ljx/.listenai/lisa-zephyr
  30.   VIRTUAL_ENV - /home/ljx/.listenai/lisa-zephyr/venv
  31.   ZEPHYR_TOOLCHAIN_VARIANT - zephyr
  32.   ZEPHYR_SDK_INSTALL_DIR - /home/ljx/.listenai/lisa-zephyr/packages/node_modules/@binary/zephyr-sdk-0.14.2/binary
  33.   GNUARMEMB_TOOLCHAIN_PATH - /home/ljx/.listenai/lisa-zephyr/packages/node_modules/@binary/gcc-arm-none-eabi-10.3/binary
复造代码
烧录过程当中呈现没法烧录的形状,usb改一下权力就行了,出发明其余成就,上脚比nano简单,Jetson经常呈现各类没法烧录的成就。
  1. cat vim /etc/udev/rules.d/50-usbcan.rules
  2. cat: vim: No such file or directory
  3. SUBSYSTEMS=="usb",
  4. ATTRS{idVendor}=="0d28",
  5. ATTRS{idProduct}=="0204",
  6. GROUP="users",
  7. MODE="0666"
  8. ls /dev/bus/usb/ -IR
  9. sudo chmod 666 /dev/bus/usb/*
  10. sudo udevadm control --reload
复造代码

【聆思CSK6 望觉AI开辟套件试用】CSK6望觉套件取Jetson ...-2.jpg

该当是不加快引擎的减持粗度借能够,民间很知心的正在头肩识别的根底上增加了人脸识别另有功用按键保留,比照以下,前期有时间能够按照源码增加自己的扩大功用。
  1. /app_algo_fd_sample_for_csk6$ ls ../app_algo_hsd_sample_for_csk6/src/
  2. bitmap.c  bitmap.h  camera_monitor.c  main.c
  3. ljx@ubuntu:~/app_algo_fd_sample_for_csk6$ cd src/
  4. ljx@ubuntu:~/app_algo_fd_sample_for_csk6/src$ ls
  5. bitmap.c  bitmap.h  button.c  button.h  camera_monitor.c  main.c  multi_button.c  multi_button.h  storage.c  storage.h
复造代码
main.c比照
  1. ljx@ubuntu:~/app_algo_hsd_sample_for_csk6/src$ diff main.c ../../app_algo_fd_sample_for_csk6/src/main.c
  2. 8a9
  3. > #include <licak/modules/fd/fd.h>
  4. 12a14
  5. > #include <zephyr/multi_heap/shared_multi_heap.h>
  6. 14c16
  7. < #define LOG_LEVEL 4
  8. ---
  9. > // #define LOG_LEVEL 4
  10. 23a26,28
  11. > #include "storage.h"
  12. > #include "button.h"
  13. >
  14. 27,30d31
  15. < // 240p
  16. < // #define IMAGE_HEIGHT 240
  17. < // #define IMAGE_WIDTH 320
  18. < // 480p
  19. 38c39
  20. < #include "input_640x480.h"
  21. ---
  22. > #include "image_640x480.h"
  23. 42a44,46
  24. > #define WEBUSB_IMAGE_DOWNSAMPLING (2)
  25. > #define WEBUSB_IMAGE_SCALE (1.0f / WEBUSB_IMAGE_DOWNSAMPLING)
  26. >
  27. 44,47c48
  28. <   hsd_head_shoulder_detect result;
  29. <   head_shoulder_detect hsd;
  30. <   uint32_t data_len;
  31. <   hsd_event event;
  32. ---
  33. >   char text[256];
  34. 50c51,61
  35. < const struct device *video;
  36. ---
  37. > typedef struct {
  38. >     float feature[FD_MAX_FEATURE_DIMS];
  39. >     float feature_nvs[FD_MAX_FEATURE_DIMS];
  40. >     bool get_new_feature;
  41. >     fd_t *fd;
  42. >     bool is_usb_cfg;
  43. >     const struct device *video;
  44. >     struct video_format fmt;
  45. >     char result_txt[512];
  46. >     struct k_msgq msg;
  47. > } face_register_t;
  48. 52c63
  49. < bool is_usb_cfg;
  50. ---
  51. > face_register_t fr;
  52. 54d64
  53. < struct k_msgq msg;
  54. 56c66,69
  55. < int64_t time;
  56. ---
  57. > #ifdef CONFIG_WEBUSB
  58. > void webusb_send_pic(struct video_buffer *vbuf, fd_face_recog_result_t *result)
  59. > {
  60. >     float scale;
  61. 58,62c71,73
  62. < void on_receive_hsd_result(hsd_t *hsd, hsd_event event, void *data,
  63. <     void *user_data) {
  64. <   if (event == HSD_EVENT_HEAD_SHOULDER) {
  65. <     hsd_head_shoulder_detect *result = (hsd_head_shoulder_detect *)data;
  66. <     LOG_INF("head shoulder cnt: %d", result->track_count);
  67. ---
  68. >     if(!fr.is_usb_cfg){
  69. >         return;
  70. >     }
  71. 64,67c75,89
  72. < #ifdef CONFIG_WEBUSB
  73. <     msg_data_t msg_data = {
  74. <       .data_len = result->len,
  75. <       .event = event,
  76. ---
  77. > #if MOCK_DATA
  78. >     scale = 1;
  79. >     img_info_t img_info = {
  80. >         .width = IMAGE_WIDTH,
  81. >         .height = IMAGE_HEIGHT,
  82. >         .format = FORMAT_BGR888,
  83. >         .scale = scale
  84. >     };
  85. > #else
  86. >     scale = WEBUSB_IMAGE_SCALE;
  87. >     img_info_t img_info = {
  88. >         .width = IMAGE_WIDTH,
  89. >         .height = IMAGE_HEIGHT,
  90. >         .format = FORMAT_VYUY_422,
  91. >         .scale = WEBUSB_IMAGE_SCALE
  92. 68a91
  93. > #endif
  94. 70c93
  95. <     memcpy(&msg_data.result, result, sizeof(msg_data.result));
  96. ---
  97. >     send_image_info(img_info);
  98. 72,76c95,139
  99. <     k_msgq_put(&msg, &msg_data, K_NO_WAIT);
  100. < #endif
  101. <   } else if (event == HSD_EVENT_GESTURE_RECOGNIZE) {
  102. <     head_shoulder_detect *result = (head_shoulder_detect *)data;
  103. <     LOG_INF("gesture result id: %d ,state: %d", result->id, result->gesture_state);
  104. ---
  105. >     //PC只显现一个
  106. >     if(result->detect_cnt > 0){
  107. >         face_t face = {
  108. >             .x = result->detect_data[0].detect_rect.x,
  109. >             .y = result->detect_data[0].detect_rect.y,
  110. >             .w = result->detect_data[0].detect_rect.w,
  111. >             .h = result->detect_data[0].detect_rect.h,
  112. >             .detect_score = result->detect_data[0].detect_score,
  113. >             .feature_dim = result->detect_data[0].feature_dim,
  114. >             .id = 1
  115. >         };
  116. >         sprintf((char *)fr.result_txt, "head_yaw: %3.0f\r\nhead_pitch: %3.0f\r\nhead_roll: %3.0f\r\nhead_pose_status: %d\r\nanti_spoofing_score: %3.2f\r\nanti_spoofing_status: %d",
  117. >                                         result->detect_data[0].head_yaw,
  118. >                                         result->detect_data[0].head_pitch,
  119. >                                         result->detect_data[0].head_roll,
  120. >                                         result->detect_data[0].head_pose_status,
  121. >                                         result->detect_data[0].anti_spoofing_score,
  122. >                                         result->detect_data[0].anti_spoofing_status);
  123. >
  124. >         send_face(face, (char *)fr.result_txt);  
  125. >     }   
  126. >
  127. >     if(scale != 1){
  128. >         uint32_t dst_width = IMAGE_WIDTH * scale;
  129. >         uint32_t dst_height = IMAGE_HEIGHT * scale;
  130. >         uint32_t data_len = dst_width * dst_height * 2;
  131. >         uint8_t *out = (uint8_t *)csk_malloc(data_len);
  132. >
  133. >         if (out == NULL) {
  134. >             LOG_ERR("Failed to alloc image buffer");
  135. >             return;
  136. >         }
  137. >
  138. >         if(img_info.format == FORMAT_BGR888){
  139. >             img_scale(vbuf->buffer, out, IMAGE_WIDTH, IMAGE_HEIGHT, scale);
  140. >         }else{
  141. >             yuv_scale(vbuf->buffer, out, IMAGE_WIDTH, IMAGE_HEIGHT, scale);
  142. >         }
  143. >         
  144. >         send_bitmap(out, data_len);
  145. >
  146. >         csk_free(out);   
  147. >     }else{
  148. >         send_bitmap(vbuf->buffer, vbuf->size);
  149. >     }
  150. 78,79c141,145
  151. < #ifdef CONFIG_WEBUSB
  152. <     msg_data_t msg_data = { .event = event };
  153. ---
  154. >     msg_data_t msg_data;
  155. >     int ret = k_msgq_get(&fr.msg, &msg_data, K_NO_WAIT);
  156. >     if (ret == 0) {
  157. >         send_message(msg_data.text);
  158. >     }
  159. 81c147
  160. <     memcpy(&msg_data.hsd, result, sizeof(msg_data.hsd));
  161. ---
  162. > }
  163. 83,85c149,172
  164. <     k_msgq_put(&msg, &msg_data, K_NO_WAIT);
  165. < #endif
  166. <   }
  167. ---
  168. > void webusb_status_callback(struct usb_cfg_data *cfg, enum usb_dc_status_code status, const uint8_t *param) {
  169. >     /* Check the USB status and do needed action if required */
  170. >     switch (status) {
  171. >         case USB_DC_ERROR:
  172. >             LOG_DBG("USB device error");
  173. >             break;
  174. >         case USB_DC_RESET:
  175. >             LOG_DBG("USB device reset detected");
  176. >             break;
  177. >         case USB_DC_CONNECTED:
  178. >             LOG_DBG("USB device connected");
  179. >             break;
  180. >         case USB_DC_CONFIGURED:
  181. >             LOG_DBG("USB device configured");
  182. >             fr.is_usb_cfg = true;
  183. >             break;
  184. >         case USB_DC_DISCONNECTED:
  185. >             LOG_DBG("USB device disconnected");
  186. >             fr.is_usb_cfg = false;
  187. >             break;
  188. >         default:
  189. >             LOG_DBG("USB unknown state");
  190. >             break;
  191. >     }
  192. 88,155c175,182
  193. < #ifdef CONFIG_WEBUSB
  194. < void handle_shoulder_data(msg_data_t msg_data) {
  195. <   if (!is_usb_cfg) {
  196. <     LOG_WRN("USB hasn't been configured yet");
  197. <     return;
  198. <   }
  199. <
  200. <   float scale = 0.25f;
  201. <
  202. <   img_info_t img_info = {
  203. <     .width = msg_data.result.width,
  204. <     .height = msg_data.result.height,
  205. <     .format = FORMAT_BGR888,
  206. <     .scale = scale
  207. <   };
  208. <
  209. <   send_image_info(img_info);
  210. <
  211. <   if (msg_data.result.track_count > 0) {
  212. <     uint32_t send_len = sizeof(shoulder_t) * msg_data.result.track_count;
  213. <     uint8_t *send = k_malloc(send_len);
  214. <
  215. <     int index = 0;
  216. <
  217. <     for (int i = 0; i < msg_data.result.track_count; i++) {
  218. <       head_shoulder_detect item = msg_data.result.result[i];
  219. <
  220. <       shoulder_t shoulder = {
  221. <         .x = item.rect.x,
  222. <         .y = item.rect.y,
  223. <         .w = item.rect.w,
  224. <         .h = item.rect.h,
  225. <         .score = item.score,
  226. <         .iou_score = item.iou_score,
  227. <         .detect_loss_cnt = item.detect_loss_cnt,
  228. <         .id = item.id,
  229. <         .loss_cnt_thres = item.loss_cnt_thres,
  230. <         .update = item.update
  231. <       };
  232. <
  233. <       uint8_t *temp = (uint8_t *)(&shoulder);
  234. <
  235. <       for (int j = 0; j < sizeof(shoulder); j++) {
  236. <         send[index] = temp[j];
  237. <         index += 1;
  238. <       }
  239. <     }
  240. <
  241. <     send_shoulder(send, send_len);
  242. <
  243. <     k_free(send);
  244. <   }
  245. <
  246. <   uint32_t dst_width = msg_data.result.width * scale;
  247. <   uint32_t dst_height = msg_data.result.height * scale;
  248. <   uint32_t data_len = dst_width * dst_height * 3;
  249. <   uint8_t *out = (uint8_t *)csk_malloc(data_len);
  250. <
  251. <   if (out == NULL) {
  252. <     LOG_ERR("Failed to alloc image buffer");
  253. <     return;
  254. <   }
  255. <
  256. <   img_scale(msg_data.result.data, out, msg_data.result.width, msg_data.result.height, scale);
  257. <
  258. <   if (send_bitmap(out, data_len) < 0) {
  259. <     LOG_WRN("send_bitmap FAILED.");
  260. <   }
  261. ---
  262. > void webusb_send_message(char *txt){
  263. >     uint32_t len = strlen(txt);
  264. >     msg_data_t *msg = csk_malloc(sizeof(msg_data_t));
  265. >     if(msg == NULL){
  266. >         LOG_ERR("[%s] failed to allocate memory", __FUNCTION__);
  267. >     }
  268. >     
  269. >     memset((void *)msg->text, 0, sizeof(msg_data_t));
  270. 157,158c184
  271. <   csk_free(out);
  272. < }
  273. ---
  274. >     memcpy((void *)msg->text, (void *)txt, len);
  275. 160,183c186,189
  276. < void webusb_status_callback(struct usb_cfg_data *cfg, enum usb_dc_status_code status, const uint8_t *param) {
  277. <   /* Check the USB status and do needed action if required */
  278. <   switch (status) {
  279. <   case USB_DC_ERROR:
  280. <     LOG_DBG("USB device error");
  281. <     break;
  282. <   case USB_DC_RESET:
  283. <     LOG_DBG("USB device reset detected");
  284. <     break;
  285. <   case USB_DC_CONNECTED:
  286. <     LOG_DBG("USB device connected");
  287. <     break;
  288. <   case USB_DC_CONFIGURED:
  289. <     LOG_DBG("USB device configured");
  290. <     is_usb_cfg = true;
  291. <     break;
  292. <   case USB_DC_DISCONNECTED:
  293. <     LOG_DBG("USB device disconnected");
  294. <     is_usb_cfg = false;
  295. <     break;
  296. <   default:
  297. <     LOG_DBG("USB unknown state");
  298. <     break;
  299. <   }
  300. ---
  301. >     k_msgq_put(&fr.msg, msg, K_NO_WAIT);
  302. >
  303. >     csk_free(msg);
  304. >  
  305. 185d190
  306. < #endif
  307. 187,189c192,193
  308. < void main(void) {
  309. < #ifdef CONFIG_WEBUSB
  310. <   register_webusb_status_cb(webusb_status_callback);
  311. ---
  312. > void button_callback(uint32_t event){
  313. >     int ret = 0;
  314. 191,194c195,259
  315. <   if (0 != webusb_enable()) {
  316. <     LOG_ERR("Failed to enable USB");
  317. <     return;
  318. <   }
  319. ---
  320. >     switch(event){
  321. >         case BUTTON_SINGLE_CLICK:
  322. >             if(fr.get_new_feature){
  323. >                 uint16_t cnt = 0;
  324. >                 uint8_t done = 0;
  325. >                 fr.get_new_feature = false;
  326. >                 
  327. >                 fd_cmd_compare_feature_data_t data;
  328. >                 fd_cmd_compare_feature_result_t result;
  329. >                 data.feature_dim = FD_MAX_FEATURE_DIMS;
  330. >                 data.feature_src = fr.feature_nvs;
  331. >                 data.feature_dst = fr.feature;
  332. >
  333. >                 storage_get_data_cnt(&cnt);
  334. >                 for(uint32_t i = 0; i < cnt; i++){
  335. >                     storage_read_data(i, (void *)fr.feature_nvs, sizeof(fr.feature));
  336. >                     ret = fd_control(fr.fd, FD_CMD_COMPARE_FEATURE, &data, &result);
  337. >                     if(ret != 0){
  338. >                         LOG_ERR("feature_compare faild %d", ret);
  339. >                     }
  340. >
  341. >                     LOG_INF("feature_compare score = %f", result.score);
  342. >                     if(result.score > 0.95){
  343. >                         done = 1;
  344. >                     }
  345. >                 }
  346. >                 if(done){
  347. >                     webusb_send_message("face_calc_similar: success");
  348. >
  349. >                 }else{
  350. >                     webusb_send_message("face_calc_similar: fail");
  351. >                 }
  352. >             }else{
  353. >                 webusb_send_message("face_calc_similar: fail");
  354. >                 LOG_INF("not detected face feature");
  355. >             }      
  356. >             break;
  357. >         case BUTTON_LONG_PRESS:
  358. >             if(fr.get_new_feature){
  359. >                 uint16_t cnt = 0;
  360. >                 fr.get_new_feature = false;
  361. >                 char *txt = csk_malloc(64);
  362. >                 
  363. >                 storage_write((void *)fr.feature, sizeof(fr.feature));
  364. >
  365. >                 storage_get_data_cnt(&cnt);
  366. >                 sprintf(txt, "face_recognize: success, count:%d", cnt);
  367. >                 webusb_send_message(txt);
  368. >                 csk_free(txt);
  369. >
  370. >                 LOG_INF("face feature save success");
  371. >             }else{
  372. >                 webusb_send_message("face_recognize: fail");
  373. >
  374. >                 LOG_INF("not detected face feature");
  375. >             }  
  376. >             break;
  377. >         case BUTTON_DOUBLE_CLICK:
  378. >             storage_clear_data();
  379. >             webusb_send_message("clear_face _data: success, count: 0");
  380. >             break;
  381. >         default:
  382. >             break;
  383. >     }
  384. > }
  385. 197,232c262,279
  386. <   if (0 != licak_init()) {
  387. <     printk("LICAK init failed,exit.\n");
  388. <     return;
  389. <   }
  390. <
  391. <   video = device_get_binding(VIDEO_DEV);
  392. <
  393. <   if (video == NULL) {
  394. <     LOG_ERR(
  395. <         "Video device %s not found, "
  396. <         "fallback to software generator.",
  397. <         VIDEO_DEV);
  398. <
  399. <     return;
  400. <   }
  401. <
  402. <   struct video_format fmt;
  403. <   fmt.pixelformat = VIDEO_PIX_FMT_VYUY;
  404. <   fmt.width = IMAGE_WIDTH;
  405. <   fmt.height = IMAGE_HEIGHT;
  406. <   fmt.pitch = fmt.width * 2;
  407. <   if (video_set_format(video, VIDEO_EP_OUT, &fmt)) {
  408. <     LOG_ERR("Unable to set video format");
  409. <     return;
  410. <   }
  411. <
  412. <   hsd_t *hsd = hsd_create(HSD_FLAG_HEAD_SHOULDER | HSD_FLAG_GESTURE_RECOGNIZE);
  413. <
  414. <   if (hsd == NULL) {
  415. <     LOG_ERR("Create HSD instance failed.");
  416. <     return;
  417. <   }
  418. <
  419. <   hsd_event_register(hsd, HSD_EVENT_HEAD_SHOULDER, on_receive_hsd_result, NULL);
  420. <   hsd_event_register(hsd, HSD_EVENT_GESTURE_RECOGNIZE, on_receive_hsd_result,
  421. <       NULL);
  422. ---
  423. > int sample_face_detect(fd_t *fd, struct video_buffer *vbuf, struct video_format *fmt)
  424. > {
  425. >     fd_face_recog_result_t result;
  426. >     pic_buffer_t pic_buf;
  427. >
  428. >     pic_buf.buffer = vbuf->buffer;
  429. >     pic_buf.size = vbuf->size;
  430. >
  431. >     memset((void *)&result, 0, sizeof(fd_face_recog_result_t));
  432. >     memcpy((void *)&pic_buf.format, (void *)fmt, sizeof(struct video_format));
  433. >
  434. >     uint8_t *buf = k_malloc(MAX_DETECT_RESULT * sizeof(fd_face_recog_data_t));
  435. >     if(!buf){
  436. >         LOG_ERR("no memory for fd_face_recog_data");
  437. >         return -1;
  438. >     }
  439. >     result.detect_data = (fd_face_recog_data_t *)buf;
  440. >     fd_exec(fd, &pic_buf, &result);
  441. 234c281,300
  442. <   printk("- Device name: %s\n", VIDEO_DEV);
  443. ---
  444. >     for(uint8_t i = 0; i < result.detect_cnt; i++) {
  445. >         if(result.detect_data[i].anti_spoofing_status){
  446. >             LOG_DBG("x = %d\t y=%d\t w=%d\t h=%d\t score=%f",
  447. >                 result.detect_data[i].detect_rect.x,
  448. >                 result.detect_data[i].detect_rect.y,
  449. >                 result.detect_data[i].detect_rect.w,
  450. >                 result.detect_data[i].detect_rect.h,
  451. >                 result.detect_data[i].detect_score);
  452. >             LOG_DBG("anti_spoofing_score:%f head_pose_status:%d", result.detect_data[i].anti_spoofing_score, result.detect_data[i].head_pose_status);
  453. >             LOG_DBG("head_yaw = %f, head_pitch = %f, head_roll = %f",
  454. >                     result.detect_data[i].head_yaw,
  455. >                     result.detect_data[i].head_pitch,
  456. >                     result.detect_data[i].head_roll);
  457. >         }
  458. >     }
  459. >
  460. >     if(result.detect_cnt != 0 && result.detect_data[0].feature_dim == FD_MAX_FEATURE_DIMS){
  461. >         memcpy((void *)fr.feature, (void *)result.detect_data[0].feature, result.detect_data[0].feature_dim * sizeof(float));
  462. >         fr.get_new_feature = true;
  463. >     }
  464. 237,239c303
  465. <   static char buffer[sizeof(msg_data_t) * MSGQ_NUMBER];
  466. <   msg_data_t msg_data;
  467. <   k_msgq_init(&msg, buffer, sizeof(msg_data_t), MSGQ_NUMBER);
  468. ---
  469. >     webusb_send_pic(vbuf, &result);
  470. 242c306
  471. <   // hsd_set_params(hsd, HSD_PARAM_HEAD_SHOULDER_DETECT_THRES, 0.55f);
  472. ---
  473. >     k_free(buf);
  474. 244,246c308,309
  475. <   // float value;
  476. <   // hsd_get_params(hsd, HSD_PARAM_HEAD_SHOULDER_DETECT_THRES, &value);
  477. <   // LOG_INF("GET_PARAMS: %d %f", HSD_PARAM_HEAD_SHOULDER_DETECT_THRES, value);
  478. ---
  479. >     return 0;
  480. > }
  481. 248,250d310
  482. < #if MOCK_DATA
  483. <   struct video_buffer *vbuf = video_buffer_alloc(IMAGE_SIZE);
  484. <   memcpy(vbuf->buffer, head_640x480, vbuf->size * sizeof(char));
  485. 252,254c312,328
  486. <   fmt.height = 480;
  487. <   fmt.width = 640;
  488. <   fmt.pixelformat = VIDEO_PIX_FMT_BGR24;
  489. ---
  490. > int video_init(void){
  491. >     const struct device *video;
  492. >     int ret = 0;
  493. >
  494. >     fr.fmt.pixelformat = VIDEO_PIX_FMT_VYUY;
  495. >     fr.fmt.width = IMAGE_WIDTH;
  496. >     fr.fmt.height = IMAGE_HEIGHT;
  497. >     fr.fmt.pitch = fr.fmt.width * 2;
  498. >
  499. >     video = device_get_binding(VIDEO_DEV);
  500. >     if (video == NULL) {
  501. >           LOG_ERR("Video device %s not found",VIDEO_DEV);
  502. >         ret = -1;
  503. >         goto error;
  504. >     }
  505. >
  506. >     LOG_INF("- Device name: %s\n", VIDEO_DEV);
  507. 256,257c330,334
  508. <   while (1) {
  509. <     hsd_exec(hsd, vbuf, fmt);
  510. ---
  511. >     if (video_set_format(video, VIDEO_EP_OUT, &fr.fmt)) {
  512. >         LOG_ERR("Unable to set video format");
  513. >         ret = -1;
  514. >         goto error;
  515. >     }
  516. 259c336,346
  517. <     k_sleep(K_MSEC(400));
  518. ---
  519. >     struct video_buffer *buffers[2];
  520. >     int bsize = fr.fmt.pitch * fr.fmt.height;
  521. >     /* Alloc video buffers and enqueue for capture */
  522. >     for (int i = 0; i < ARRAY_SIZE(buffers); i++) {
  523. >         LOG_INF("Alloc video buffer: %d", bsize);
  524. >         buffers[i] = video_buffer_alloc(bsize);
  525. >         if (buffers[i] == NULL) {
  526. >             LOG_ERR("Unable to alloc video buffer");
  527. >             ret = -1;
  528. >             goto error;
  529. >         }
  530. 261,265c348
  531. < #ifdef CONFIG_WEBUSB
  532. <     int ret = k_msgq_get(&msg, &msg_data, K_MSEC(500));
  533. <     if (ret != 0) {
  534. <       LOG_WRN("Get video buffer timeout.");
  535. <       continue;
  536. ---
  537. >           video_enqueue(video, VIDEO_EP_OUT, buffers[i]);
  538. 267,270d349
  539. < #endif
  540. <   }
  541. < #else
  542. <   hsd_start(hsd, video);
  543. 272,295c351,362
  544. <   while (1) {
  545. < #ifdef CONFIG_WEBUSB
  546. <     int ret = k_msgq_get(&msg, &msg_data, K_FOREVER);
  547. <     if (ret != 0) {
  548. <       LOG_WRN("Get video buffer timeout.");
  549. <       continue;
  550. <     }
  551. <
  552. <     switch (msg_data.event) {
  553. <     case HSD_EVENT_HEAD_SHOULDER:
  554. <       handle_shoulder_data(msg_data);
  555. <       break;
  556. <     case HSD_EVENT_GESTURE_RECOGNIZE:
  557. <       if (is_usb_cfg && msg_data.hsd.gesture_state >= 0 && msg_data.hsd.gesture_state <= 5) {
  558. <         gesture_t gesture = {
  559. <           .x = msg_data.hsd.rect.x,
  560. <           .y = msg_data.hsd.rect.y,
  561. <           .w = msg_data.hsd.rect.w,
  562. <           .h = msg_data.hsd.rect.h,
  563. <           .gesture = msg_data.hsd.gesture_state,
  564. <           .score = msg_data.hsd.gesture_scores[msg_data.hsd.gesture_state],
  565. <           .status = msg_data.hsd.gesture_status[msg_data.hsd.gesture_state],
  566. <           .id = msg_data.hsd.id
  567. <         };
  568. ---
  569. >     /* Start video capture */
  570. >     if (video_stream_start(video)) {
  571. >       LOG_ERR("Unable to start capture (interface)");
  572. >         ret = -1;
  573. >         goto error;
  574. >     }
  575. >
  576. >     fr.video = video;
  577. >
  578. > error:
  579. >     return ret;
  580. > }
  581. 297c364,373
  582. <         uint8_t *send = (uint8_t *)(&gesture);
  583. ---
  584. > int alago_init(void){
  585. >     int ret = 0;
  586. >     fd_config_t cfg;
  587. >     fd_t *fd;
  588. >
  589. >     if (0 != licak_init()) {
  590. >         LOG_ERR("LICAK init failed,exit.\n");
  591. >         ret = -1;
  592. >         goto error;
  593. >     }
  594. 299,303c375,381
  595. <         send_gesture(send, sizeof(gesture));
  596. <       }
  597. <       break;
  598. <     default:
  599. <       break;
  600. ---
  601. >     
  602. >     cfg.algo = FD_ALGO_FACE_RECOGNIZE;
  603. >     fd = fd_create((void *)&cfg);
  604. >     if(fd  == NULL) {
  605. >         LOG_ERR("fd create failed");
  606. >         ret = -1;
  607. >         goto error;
  608. 304a383,430
  609. >
  610. >     fr.fd = fd;
  611. >
  612. >     float value = 0.4;
  613. >     fd_set_params(fd, FD_PARAM_FACE_DETECT_THRES, &value);  
  614. >
  615. >     value = 0.4;
  616. >     fd_set_params(fd, FD_PARAM_FACE_DETECT_PROBTHRES, &value);
  617. >
  618. >     value = 30.0;
  619. >     fd_set_params(fd, FD_PARAM_FACE_ALIGN_YAWTHRES, &value);
  620. >
  621. >     value = 30.0;
  622. >     fd_set_params(fd, FD_PARAM_FACE_ALIGN_PITCHTHRES, &value);
  623. >
  624. >     value = 30.0;
  625. >     fd_set_params(fd, FD_PARAM_FACE_ALIGN_ROLLTHRES, &value);
  626. >
  627. >     value = 0.7;
  628. >     fd_set_params(fd, FD_PARAM_ANTI_SPOOFING_THRES, &value);   
  629. >
  630. > error:
  631. >     return ret;
  632. > }
  633. >
  634. > void main(void){
  635. >     struct video_buffer *vbuf;
  636. >
  637. > #ifdef CONFIG_WEBUSB
  638. >     static char buffer[sizeof(msg_data_t) * MSGQ_NUMBER];
  639. >     k_msgq_init(&fr.msg, buffer, sizeof(msg_data_t), MSGQ_NUMBER);
  640. >
  641. >     register_webusb_status_cb(webusb_status_callback);
  642. >     if (0 != webusb_enable()) {
  643. >         LOG_ERR("Failed to enable USB");
  644. >         return;
  645. >     }
  646. >
  647. >     storage_init();
  648. >
  649. >     register_button_event(button_callback);
  650. >     button_proc(button_callback);
  651. > #endif
  652. >
  653. > #if !MOCK_DATA
  654. >     if(video_init()){
  655. >         return;
  656. >     }
  657. 306c432,438
  658. <     k_msleep(10);
  659. ---
  660. >     vbuf = video_buffer_alloc(IMAGE_SIZE);
  661. >     if(!vbuf){
  662. >         LOG_ERR("Failed to alloc video buffer");
  663. >         return;
  664. >     }
  665. >     vbuf->size = sizeof(image_640x480_resource)/sizeof(image_640x480_resource[0]);
  666. >     memcpy(vbuf->buffer, image_640x480_resource, vbuf->size);
  667. 308d439
  668. <   }
  669. 310c441,454
  670. <   hsd_stop(hsd);
  671. ---
  672. >     if(alago_init()){
  673. >         return;
  674. >     }
  675. >
  676. >     uint32_t last = k_uptime_get_32();
  677. >     uint32_t time = k_uptime_get_32();
  678. >
  679. >     while(1){
  680. > #if MOCK_DATA
  681. >         struct video_format fmt;
  682. >         fmt.width = IMAGE_WIDTH;
  683. >         fmt.height = IMAGE_HEIGHT;
  684. >         fmt.pitch = fmt.width * 2;
  685. >         fmt.pixelformat = VIDEO_PIX_FMT_RGB24;
  686. 312c456,465
  687. <   hsd_destroy(hsd);
  688. ---
  689. >         sample_face_detect(fr.fd, vbuf, &fmt);
  690. > #else
  691. >         if (video_dequeue(fr.video, VIDEO_EP_OUT, &vbuf, K_FOREVER)) {
  692. >             LOG_ERR("Unable to dequeue video buf");
  693. >             break;
  694. >         }
  695. >
  696. >         sample_face_detect(fr.fd, vbuf, &fr.fmt);
  697. >
  698. >         video_enqueue(fr.video, VIDEO_EP_OUT, vbuf);
  699. 315c468,471
  700. <   LOG_DBG("AP EXEC END\n");
  701. ---
  702. >         last = time;
  703. >         time = k_uptime_get_32();
  704. >         LOG_DBG("FPS: %.2f", 1000.0 / (time - last));
  705. >     }
复造代码

【聆思CSK6 望觉AI开辟套件试用】CSK6望觉套件取Jetson ...-3.jpg

头肩识别
CSK6的价钱关于Jetson Nano来讲没有到六分之一,固然正在死态上撑持的算法框架借近不敷,进修来讲必然是比nano要喷鼻,异常正在装备树文献战源码也是启源的形状下分类简朴,洞若观火。
您需要登录后才可以回帖 登录 | 立即注册 qq_login

本版积分规则

发布主题
阅读排行更多+
用专业创造成效
400-778-7781
周一至周五 9:00-18:00
意见反馈:server@mailiao.group
紧急联系:181-67184787
ftqrcode

扫一扫关注我们

Powered by 职贝云数A新零售门户 X3.5© 2004-2025 职贝云数 Inc.( 蜀ICP备2024104722号 )