![](/media/cache/group/renesas_logomark_l.jpg.50x50_q85.jpg)
Sample program that can send the recognition data from HVC-P2 to Fujitsu IoT Platform using REST (HTTP)
Dependencies: AsciiFont GR-PEACH_video GraphicsFramework LCD_shield_config R_BSP USBHost_custom easy-connect-gr-peach mbed-http picojson
Information
Here are both English and Japanese description. First, English description is shown followed by Japanese one. 本ページには英語版と日本語版の説明があります。まず英語版、続いて日本語版の説明となります。
Overview
This sample program shows how to send the cognitive data gathered by Omron HVC-P2 (Human Vision Components B5T-007001) to IoT Platform managed by FUJITSU ( http://jp.fujitsu.com/solutions/cloud/k5/function/paas/iot-platform/ ).
Hardware Configuration
- GR-PEACH 1 set ( https://developer.mbed.org/platforms/Renesas-GR-PEACH/ )
- LCD Shield 1 set ( https://developer.mbed.org/teams/Renesas/Wiki/LCD-shield )
- HVC-P2 1 set ( Human Vision Components B5T-007001 ) ( https://plus-sensin.omron.com/product/B5T-007001/ )
- USBA - Micro USB Cable 2 sets
- USBA (Female) - Micro USB (Male) Adapter 1 set
When executing this sample program, please configure the above H/W as shown below:
Also, please close JP3 of GR-PEACH as follows:
Application Preconfiguration
- Configure Ethernet settings. For details, please refer to the following link:
https://developer.mbed.org/teams/Renesas/code/GR-PEACH_IoT_Platform_HTTP_sample/wiki/Ethernet-settings - On IoT Platform, set up the resource and its access code where the gathered data would be stored. For details on resource and access code, please refer to the following links:
https://iot-docs.jp-east-1.paas.cloud.global.fujitsu.com/en/manual/userguide_en.pdf
https://iot-docs.jp-east-1.paas.cloud.global.fujitsu.com/en/manual/apireference_en.pdf
https://iot-docs.jp-east-1.paas.cloud.global.fujitsu.com/en/manual/portalmanual_en.pdf
Build Procedure
- Import this sample program onto mbed Compiler
- In GR-PEACH_HVC-P2_IoTPlatform_http/IoT_Platform/iot_platform.cpp, please replace <ACCESS CODE> with the access code you set up on IoT Platform. For details on how to set up Access Code, please refer to the above Application Setup. Then, please delete the line beginning with #error macro.
Access Code configuration
#define ACCESS_CODE <Access CODE> #error "You need to replace <Access CODE for your resource> with yours"
- In GR-PEACH_HVC-P2_IoTPlatform_http/IoT_Platform/iot_platform.cpp, please replace <Base URI>, <Tenant ID> and <Path-to-Resource> below with yours and delete the line beginning with #error macro. For details on <Base URI> and <Tenant ID>, please contact FUJITSU LIMITED. Also, for details on <Path-to-Resource>, please refer to the above Application Setup.
URI configuration
std::string put_uri_base("<Base URI>/v1/<Tenant ID>/<Path-to-Resource>.json"); #error "You need to replace <Base URI>, <Tenant ID> and <Path-to-Resource> with yours" **snip** std::string get_uri("<Base URI>/v1/<Tenant ID>/<Path-to-Resource>/_past.json"); #error "You need to replace <Base URI>, <Tenant ID> and <Path-to-Resource> with yours"
- Compile the program. If compilation is successfully terminated, the binary should be downloaded on your PC.
- Plug Ethernet cable into GR-PEACH
- Plug micro-USB cable into the port which lies on the next to RESET button. If GR-PEACH is successfully recognized, it appears as the USB flash disk named mbed as show below:
- Copy the downloaded binary to mbed drive
- Press RESET button on GR-PEACH in order to run the program. If it's successfully run, you can see the following message on terminal:
Format of Data to be sent to IoT Platform
In this program, the cognitive data sent from HVC-P2 is serialized in the following JSON format and send it to IoT Platform:
- Face detection data
{ "RecodeType": "HVC-P2(face)" "id": <GR-PEACH ID>-<Sensor ID>" "FaceRectangle": { "Height": xxxx, "Left": xxxx, "Top": xxxx, "Width": xxxx, }, "Gender": "male" or "female", "Scores": { "Anger": zzz, "Hapiness": zzz, "Neutral": zzz, "Sadness": zzz, "Surprise": zzz } } xxxx: Top-left coordinate, width and height of the rectangle circumscribing the detected face in LCD display coordinate system zzz: the value indicating the expression estimated from the detected face
//
- Body detection data
{ "RecodeType": "HVC-P2(body)" "id": <GR-PEACH ID>-<Sensor ID>" "BodyRectangle": { "Height": xxxx, "Left": xxxx, "Top": xxxx, "Width": xxxx, } } xxxx: Top-left coordinate, width and height of the rectangle circumscribing the detected body in LCD display coordinate system
概要
本プログラムは、オムロン社製HVC-P2 (Human Vision Components B5T-007001)で収集した各種認識データを、富士通社のIoT Platform ( http://jp.fujitsu.com/solutions/cloud/k5/function/paas/iot-platform/ ) に送信するサンプルプログラムです。
ハードウェア構成
- GR-PEACH 1式 ( https://developer.mbed.org/platforms/Renesas-GR-PEACH/ )
- LCD Shield 1式 ( https://developer.mbed.org/teams/Renesas/Wiki/LCD-shield )
- HVC-P2 1式 ( Human Vision Components B5T-007001 ) ( https://plus-sensin.omron.com/product/B5T-007001/ )
- USBA - Micro USBケーブル 2式
- USBA (メス) - Micro USB (オス)変換アダプタ 1式
本プログラムを動作させる場合、上記H/Wを下図のように接続してください。
また下図に示すGR-PEACHのJP3をショートしてください。
アプリケーションの事前設定
- Ethernetの設定を行います。詳細は下記リンクを参照ください。
https://developer.mbed.org/teams/Renesas/code/GR-PEACH_IoT_Platform_HTTP_sample/wiki/Ethernet-settings - HVC-P2で収集したデータを格納するリソース、およびそのアクセスコードをIoT Platform上で設定します。詳細は下記リンクを参照ください。
https://iot-docs.jp-east-1.paas.cloud.global.fujitsu.com/en/manual/userguide_en.pdf https://iot-docs.jp-east-1.paas.cloud.global.fujitsu.com/en/manual/apireference_en.pdf https://iot-docs.jp-east-1.paas.cloud.global.fujitsu.com/en/manual/portalmanual_en.pdf
ビルド手順
- 本サンプルプログラムをmbed Compilerにインポートします
- 下記に示すGR-PEACH_HVC-P2_IoTPlatform_http/IoT_Platform/iot_platform.cpp中の<ACCESS CODE> を、IoT Platform上で設定したアクセスコードで上書きしてください。<Access Code>の設定方法につきましては、上述のApplication Setupを参照願います。また #errorマクロで始まる行を削除してください。
Access Code configuration
#define ACCESS_CODE <Access CODE> #error "You need to replace <Access CODE for your resource> with yours"
- 下記に示すGR-PEACH_HVC-P2_IoTPlatform_http/IoT_Platform/iot_platform.cpp中の<Base URI>と <Tenant ID>、および<Path-to-Resource>>を適当な値に置換えるとともに、#errorマクロで始まる行を削除してください。ここで、<Base URI>、 <Tenant ID>の詳細につきましては富士通社へご確認願います。また<Path-to-Resource>>につきましては、Application Setupの項を参照ください。
URI configuration
std::string put_uri_base("<Base URI>/v1/<Tenant ID>/<Path-to-Resource>.json"); #error "You need to replace <Base URI>, <Tenant ID> and <Path-to-Resource> with yours" (中略) std::string get_uri("<Base URI>/v1/<Tenant ID>/<Path-to-Resource>/_past.json"); #error "You need to replace <Base URI>, <Tenant ID> and <Path-to-Resource> with yours"
- プログラムをコンパイルします。コンパイルが正常終了すると、バイナリがお使いのPCにダウンロードされます。
- GR-PEACHのRJ-45コネクタにEthernetケーブルを差し込んでください。
- USBA - Micro USBケーブルを、GR-PEACHのRESETボタンの隣に配置されたMicro USBポートに差し込んでください。GR-PEACHが正常に認識されると、下図に示すようにGR-PEACHがmbedという名称のUSBドライブとして認識されます。
- ダウンロードしたバイナリをmbedドライブにコピーします。
- RESETボタンを押下してプログラムを実行します。正常に実行された場合、下記に示すメッセージがターミナル上に表示されます。
送信データフォーマット
本プログラムでは、HVC-P2が収集した認識データを下記のJSONフォーマットにシリアライズし、IoT Platformへ送信します。
- Face detection data
{ "RecodeType": "HVC-P2(face)" "id": <GR-PEACH ID>-<Sensor ID>" "FaceRectangle": { "Height": xxxx, "Left": xxxx, "Top": xxxx, "Width": xxxx, }, "Gender": "male" or "female", "Scores": { "Anger": zzz, "Hapiness": zzz, "Neutral": zzz, "Sadness": zzz, "Surprise": zzz } } xxxx: LCD表示座標系における検出した顔に外接する矩形の左上座標・幅・高さ zzz: 検出した顔から推定した各種感情を示す数値
//
- Body detection data
{ "RecodeType": "HVC-P2(body)" "id": <GR-PEACH ID>-<Sensor ID>" "BodyRectangle": { "Height": xxxx, "Left": xxxx, "Top": xxxx, "Width": xxxx, } } xxxx: LCD表示座標系における検出した人体に外接する矩形の左上座標・幅・高さ
recognition_proc/recognition_proc.cpp@0:813a237f1c50, 2017-09-07 (annotated)
- Committer:
- Osamu Nakamura
- Date:
- Thu Sep 07 18:15:54 2017 +0900
- Revision:
- 0:813a237f1c50
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Osamu Nakamura |
0:813a237f1c50 | 1 | #include "mbed.h" |
Osamu Nakamura |
0:813a237f1c50 | 2 | #include "DisplayBace.h" |
Osamu Nakamura |
0:813a237f1c50 | 3 | #include "rtos.h" |
Osamu Nakamura |
0:813a237f1c50 | 4 | #include "AsciiFont.h" |
Osamu Nakamura |
0:813a237f1c50 | 5 | #include "USBHostSerial.h" |
Osamu Nakamura |
0:813a237f1c50 | 6 | #include "LCD_shield_config_4_3inch.h" |
Osamu Nakamura |
0:813a237f1c50 | 7 | #include "recognition_proc.h" |
Osamu Nakamura |
0:813a237f1c50 | 8 | #include "iot_platform.h" |
Osamu Nakamura |
0:813a237f1c50 | 9 | |
Osamu Nakamura |
0:813a237f1c50 | 10 | #define UART_SETTING_TIMEOUT 1000 /* HVC setting command signal timeout period */ |
Osamu Nakamura |
0:813a237f1c50 | 11 | #define UART_REGIST_EXECUTE_TIMEOUT 7000 /* HVC registration command signal timeout period */ |
Osamu Nakamura |
0:813a237f1c50 | 12 | #define UART_EXECUTE_TIMEOUT 10000 /* HVC execute command signal timeout period */ |
Osamu Nakamura |
0:813a237f1c50 | 13 | |
Osamu Nakamura |
0:813a237f1c50 | 14 | #define SENSOR_ROLL_ANGLE_DEFAULT 0 /* Camera angle setting */ |
Osamu Nakamura |
0:813a237f1c50 | 15 | #define USER_ID_NUM_MAX 10 |
Osamu Nakamura |
0:813a237f1c50 | 16 | |
Osamu Nakamura |
0:813a237f1c50 | 17 | #define ERROR_02 "Error: Number of detected faces is 2 or more" |
Osamu Nakamura |
0:813a237f1c50 | 18 | |
Osamu Nakamura |
0:813a237f1c50 | 19 | #define DISP_PIXEL_WIDTH (320) |
Osamu Nakamura |
0:813a237f1c50 | 20 | #define DISP_PIXEL_HEIGHT (240) |
Osamu Nakamura |
0:813a237f1c50 | 21 | |
Osamu Nakamura |
0:813a237f1c50 | 22 | /*! Frame buffer stride: Frame buffer stride should be set to a multiple of 32 or 128 |
Osamu Nakamura |
0:813a237f1c50 | 23 | in accordance with the frame buffer burst transfer mode. */ |
Osamu Nakamura |
0:813a237f1c50 | 24 | /* FRAME BUFFER Parameter GRAPHICS_LAYER_0 */ |
Osamu Nakamura |
0:813a237f1c50 | 25 | #define FRAME_BUFFER_BYTE_PER_PIXEL (2u) |
Osamu Nakamura |
0:813a237f1c50 | 26 | #define FRAME_BUFFER_STRIDE (((DISP_PIXEL_WIDTH * FRAME_BUFFER_BYTE_PER_PIXEL) + 31u) & ~31u) |
Osamu Nakamura |
0:813a237f1c50 | 27 | |
Osamu Nakamura |
0:813a237f1c50 | 28 | /* RESULT BUFFER Parameter GRAPHICS_LAYER_1 */ |
Osamu Nakamura |
0:813a237f1c50 | 29 | #define RESULT_BUFFER_BYTE_PER_PIXEL (2u) |
Osamu Nakamura |
0:813a237f1c50 | 30 | #define RESULT_BUFFER_STRIDE (((DISP_PIXEL_WIDTH * RESULT_BUFFER_BYTE_PER_PIXEL) + 31u) & ~31u) |
Osamu Nakamura |
0:813a237f1c50 | 31 | |
Osamu Nakamura |
0:813a237f1c50 | 32 | static bool registrationr_req = false; |
Osamu Nakamura |
0:813a237f1c50 | 33 | static bool setting_req = false; |
Osamu Nakamura |
0:813a237f1c50 | 34 | static recognition_setting_t setting = { |
Osamu Nakamura |
0:813a237f1c50 | 35 | 0x1FF, |
Osamu Nakamura |
0:813a237f1c50 | 36 | { BODY_THRESHOLD_DEFAULT, HAND_THRESHOLD_DEFAULT, FACE_THRESHOLD_DEFAULT, REC_THRESHOLD_DEFAULT}, |
Osamu Nakamura |
0:813a237f1c50 | 37 | { BODY_SIZE_RANGE_MIN_DEFAULT, BODY_SIZE_RANGE_MAX_DEFAULT, HAND_SIZE_RANGE_MIN_DEFAULT, |
Osamu Nakamura |
0:813a237f1c50 | 38 | HAND_SIZE_RANGE_MAX_DEFAULT, FACE_SIZE_RANGE_MIN_DEFAULT, FACE_SIZE_RANGE_MAX_DEFAULT}, |
Osamu Nakamura |
0:813a237f1c50 | 39 | FACE_POSE_DEFAULT, |
Osamu Nakamura |
0:813a237f1c50 | 40 | FACE_ANGLE_DEFAULT |
Osamu Nakamura |
0:813a237f1c50 | 41 | }; |
Osamu Nakamura |
0:813a237f1c50 | 42 | static USBHostSerial serial; |
Osamu Nakamura |
0:813a237f1c50 | 43 | static InterruptIn button(USER_BUTTON0); |
Osamu Nakamura |
0:813a237f1c50 | 44 | |
Osamu Nakamura |
0:813a237f1c50 | 45 | #if defined(__ICCARM__) |
Osamu Nakamura |
0:813a237f1c50 | 46 | /* 32 bytes aligned */ |
Osamu Nakamura |
0:813a237f1c50 | 47 | #pragma data_alignment=32 |
Osamu Nakamura |
0:813a237f1c50 | 48 | static uint8_t user_frame_buffer0[FRAME_BUFFER_STRIDE * DISP_PIXEL_HEIGHT]@ ".mirrorram"; |
Osamu Nakamura |
0:813a237f1c50 | 49 | #pragma data_alignment=32 |
Osamu Nakamura |
0:813a237f1c50 | 50 | static uint8_t user_frame_buffer_result[RESULT_BUFFER_STRIDE * DISP_PIXEL_HEIGHT]@ ".mirrorram"; |
Osamu Nakamura |
0:813a237f1c50 | 51 | #else |
Osamu Nakamura |
0:813a237f1c50 | 52 | /* 32 bytes aligned */ |
Osamu Nakamura |
0:813a237f1c50 | 53 | static uint8_t user_frame_buffer0[FRAME_BUFFER_STRIDE * DISP_PIXEL_HEIGHT]__attribute((section("NC_BSS"),aligned(32))); |
Osamu Nakamura |
0:813a237f1c50 | 54 | static uint8_t user_frame_buffer_result[RESULT_BUFFER_STRIDE * LCD_PIXEL_HEIGHT]__attribute((section("NC_BSS"),aligned(32))); |
Osamu Nakamura |
0:813a237f1c50 | 55 | #endif |
Osamu Nakamura |
0:813a237f1c50 | 56 | |
Osamu Nakamura |
0:813a237f1c50 | 57 | static AsciiFont ascii_font(user_frame_buffer_result, DISP_PIXEL_WIDTH, LCD_PIXEL_HEIGHT, |
Osamu Nakamura |
0:813a237f1c50 | 58 | RESULT_BUFFER_STRIDE, RESULT_BUFFER_BYTE_PER_PIXEL, 0x00000090); |
Osamu Nakamura |
0:813a237f1c50 | 59 | static INT32 imageNo_setting = HVC_EXECUTE_IMAGE_QVGA_HALF; |
Osamu Nakamura |
0:813a237f1c50 | 60 | static int str_draw_x = 0; |
Osamu Nakamura |
0:813a237f1c50 | 61 | static int str_draw_y = 0; |
Osamu Nakamura |
0:813a237f1c50 | 62 | |
Osamu Nakamura |
0:813a237f1c50 | 63 | /* IoT ready semaphore */ |
Osamu Nakamura |
0:813a237f1c50 | 64 | Semaphore iot_ready_semaphore(1); |
Osamu Nakamura |
0:813a237f1c50 | 65 | int semaphore_wait_ret; |
Osamu Nakamura |
0:813a237f1c50 | 66 | |
Osamu Nakamura |
0:813a237f1c50 | 67 | /****** Image Recognition ******/ |
Osamu Nakamura |
0:813a237f1c50 | 68 | extern "C" int UART_SendData(int inDataSize, UINT8 *inData) { |
Osamu Nakamura |
0:813a237f1c50 | 69 | return serial.writeBuf((char *)inData, inDataSize); |
Osamu Nakamura |
0:813a237f1c50 | 70 | } |
Osamu Nakamura |
0:813a237f1c50 | 71 | |
Osamu Nakamura |
0:813a237f1c50 | 72 | extern "C" int UART_ReceiveData(int inTimeOutTime, int inDataSize, UINT8 *outResult) { |
Osamu Nakamura |
0:813a237f1c50 | 73 | return serial.readBuf((char *)outResult, inDataSize, inTimeOutTime); |
Osamu Nakamura |
0:813a237f1c50 | 74 | } |
Osamu Nakamura |
0:813a237f1c50 | 75 | |
Osamu Nakamura |
0:813a237f1c50 | 76 | void SetRegistrationrReq(void) { |
Osamu Nakamura |
0:813a237f1c50 | 77 | registrationr_req = true; |
Osamu Nakamura |
0:813a237f1c50 | 78 | } |
Osamu Nakamura |
0:813a237f1c50 | 79 | |
Osamu Nakamura |
0:813a237f1c50 | 80 | void SetSettingReq(void) { |
Osamu Nakamura |
0:813a237f1c50 | 81 | setting_req = true; |
Osamu Nakamura |
0:813a237f1c50 | 82 | } |
Osamu Nakamura |
0:813a237f1c50 | 83 | |
Osamu Nakamura |
0:813a237f1c50 | 84 | recognition_setting_t * GetRecognitionSettingPointer(void) { |
Osamu Nakamura |
0:813a237f1c50 | 85 | return &setting; |
Osamu Nakamura |
0:813a237f1c50 | 86 | } |
Osamu Nakamura |
0:813a237f1c50 | 87 | |
Osamu Nakamura |
0:813a237f1c50 | 88 | static void EraseImage(void) { |
Osamu Nakamura |
0:813a237f1c50 | 89 | uint32_t i = 0; |
Osamu Nakamura |
0:813a237f1c50 | 90 | while (i < sizeof(user_frame_buffer0)) { |
Osamu Nakamura |
0:813a237f1c50 | 91 | user_frame_buffer0[i++] = 0x10; |
Osamu Nakamura |
0:813a237f1c50 | 92 | user_frame_buffer0[i++] = 0x80; |
Osamu Nakamura |
0:813a237f1c50 | 93 | } |
Osamu Nakamura |
0:813a237f1c50 | 94 | } |
Osamu Nakamura |
0:813a237f1c50 | 95 | |
Osamu Nakamura |
0:813a237f1c50 | 96 | static void DrawImage(int x, int y, int nWidth, int nHeight, UINT8 *unImageBuffer, int magnification) { |
Osamu Nakamura |
0:813a237f1c50 | 97 | int idx_base; |
Osamu Nakamura |
0:813a237f1c50 | 98 | int idx_w = 0; |
Osamu Nakamura |
0:813a237f1c50 | 99 | int wk_tmp = 0; |
Osamu Nakamura |
0:813a237f1c50 | 100 | int i; |
Osamu Nakamura |
0:813a237f1c50 | 101 | int j; |
Osamu Nakamura |
0:813a237f1c50 | 102 | int k; |
Osamu Nakamura |
0:813a237f1c50 | 103 | int idx_r = 0; |
Osamu Nakamura |
0:813a237f1c50 | 104 | |
Osamu Nakamura |
0:813a237f1c50 | 105 | if (magnification <= 0) { |
Osamu Nakamura |
0:813a237f1c50 | 106 | return; |
Osamu Nakamura |
0:813a237f1c50 | 107 | } |
Osamu Nakamura |
0:813a237f1c50 | 108 | |
Osamu Nakamura |
0:813a237f1c50 | 109 | idx_base = (x + (DISP_PIXEL_WIDTH * y)) * RESULT_BUFFER_BYTE_PER_PIXEL; |
Osamu Nakamura |
0:813a237f1c50 | 110 | |
Osamu Nakamura |
0:813a237f1c50 | 111 | for (i = 0; i < nHeight; i++) { |
Osamu Nakamura |
0:813a237f1c50 | 112 | idx_w = idx_base + (DISP_PIXEL_WIDTH * RESULT_BUFFER_BYTE_PER_PIXEL * i) * magnification; |
Osamu Nakamura |
0:813a237f1c50 | 113 | wk_tmp = idx_w; |
Osamu Nakamura |
0:813a237f1c50 | 114 | for (j = 0; j < nWidth; j++) { |
Osamu Nakamura |
0:813a237f1c50 | 115 | for (k = 0; k < magnification; k++) { |
Osamu Nakamura |
0:813a237f1c50 | 116 | user_frame_buffer0[idx_w] = unImageBuffer[idx_r]; |
Osamu Nakamura |
0:813a237f1c50 | 117 | idx_w += 2; |
Osamu Nakamura |
0:813a237f1c50 | 118 | } |
Osamu Nakamura |
0:813a237f1c50 | 119 | idx_r++; |
Osamu Nakamura |
0:813a237f1c50 | 120 | } |
Osamu Nakamura |
0:813a237f1c50 | 121 | for (k = 1; k < magnification; k++) { |
Osamu Nakamura |
0:813a237f1c50 | 122 | memcpy(&user_frame_buffer0[wk_tmp + (DISP_PIXEL_WIDTH * RESULT_BUFFER_BYTE_PER_PIXEL * k)], &user_frame_buffer0[wk_tmp], idx_w - wk_tmp); |
Osamu Nakamura |
0:813a237f1c50 | 123 | } |
Osamu Nakamura |
0:813a237f1c50 | 124 | } |
Osamu Nakamura |
0:813a237f1c50 | 125 | } |
Osamu Nakamura |
0:813a237f1c50 | 126 | |
Osamu Nakamura |
0:813a237f1c50 | 127 | static void DrawSquare(int x, int y, int size, uint32_t const colour) { |
Osamu Nakamura |
0:813a237f1c50 | 128 | int wk_x; |
Osamu Nakamura |
0:813a237f1c50 | 129 | int wk_y; |
Osamu Nakamura |
0:813a237f1c50 | 130 | int wk_w = 0; |
Osamu Nakamura |
0:813a237f1c50 | 131 | int wk_h = 0; |
Osamu Nakamura |
0:813a237f1c50 | 132 | int idx_base; |
Osamu Nakamura |
0:813a237f1c50 | 133 | int wk_idx; |
Osamu Nakamura |
0:813a237f1c50 | 134 | int i; |
Osamu Nakamura |
0:813a237f1c50 | 135 | int j; |
Osamu Nakamura |
0:813a237f1c50 | 136 | uint8_t coller_pix[RESULT_BUFFER_BYTE_PER_PIXEL]; /* ARGB4444 */ |
Osamu Nakamura |
0:813a237f1c50 | 137 | bool l_draw = true; |
Osamu Nakamura |
0:813a237f1c50 | 138 | bool r_draw = true; |
Osamu Nakamura |
0:813a237f1c50 | 139 | bool t_draw = true; |
Osamu Nakamura |
0:813a237f1c50 | 140 | bool b_draw = true; |
Osamu Nakamura |
0:813a237f1c50 | 141 | |
Osamu Nakamura |
0:813a237f1c50 | 142 | if ((x - (size / 2)) < 0) { |
Osamu Nakamura |
0:813a237f1c50 | 143 | l_draw = false; |
Osamu Nakamura |
0:813a237f1c50 | 144 | wk_w += x; |
Osamu Nakamura |
0:813a237f1c50 | 145 | wk_x = 0; |
Osamu Nakamura |
0:813a237f1c50 | 146 | } else { |
Osamu Nakamura |
0:813a237f1c50 | 147 | wk_w += (size / 2); |
Osamu Nakamura |
0:813a237f1c50 | 148 | wk_x = x - (size / 2); |
Osamu Nakamura |
0:813a237f1c50 | 149 | } |
Osamu Nakamura |
0:813a237f1c50 | 150 | |
Osamu Nakamura |
0:813a237f1c50 | 151 | if ((x + (size / 2)) >= 1600) { |
Osamu Nakamura |
0:813a237f1c50 | 152 | r_draw = false; |
Osamu Nakamura |
0:813a237f1c50 | 153 | wk_w += (1600 - x); |
Osamu Nakamura |
0:813a237f1c50 | 154 | } else { |
Osamu Nakamura |
0:813a237f1c50 | 155 | wk_w += (size / 2); |
Osamu Nakamura |
0:813a237f1c50 | 156 | } |
Osamu Nakamura |
0:813a237f1c50 | 157 | |
Osamu Nakamura |
0:813a237f1c50 | 158 | if ((y - (size / 2)) < 0) { |
Osamu Nakamura |
0:813a237f1c50 | 159 | t_draw = false; |
Osamu Nakamura |
0:813a237f1c50 | 160 | wk_h += y; |
Osamu Nakamura |
0:813a237f1c50 | 161 | wk_y = 0; |
Osamu Nakamura |
0:813a237f1c50 | 162 | } else { |
Osamu Nakamura |
0:813a237f1c50 | 163 | wk_h += (size / 2); |
Osamu Nakamura |
0:813a237f1c50 | 164 | wk_y = y - (size / 2); |
Osamu Nakamura |
0:813a237f1c50 | 165 | } |
Osamu Nakamura |
0:813a237f1c50 | 166 | |
Osamu Nakamura |
0:813a237f1c50 | 167 | if ((y + (size / 2)) >= 1200) { |
Osamu Nakamura |
0:813a237f1c50 | 168 | b_draw = false; |
Osamu Nakamura |
0:813a237f1c50 | 169 | wk_h += (1200 - y); |
Osamu Nakamura |
0:813a237f1c50 | 170 | } else { |
Osamu Nakamura |
0:813a237f1c50 | 171 | wk_h += (size / 2); |
Osamu Nakamura |
0:813a237f1c50 | 172 | } |
Osamu Nakamura |
0:813a237f1c50 | 173 | |
Osamu Nakamura |
0:813a237f1c50 | 174 | wk_x = wk_x / 5; |
Osamu Nakamura |
0:813a237f1c50 | 175 | wk_y = wk_y / 5; |
Osamu Nakamura |
0:813a237f1c50 | 176 | wk_w = wk_w / 5; |
Osamu Nakamura |
0:813a237f1c50 | 177 | wk_h = wk_h / 5; |
Osamu Nakamura |
0:813a237f1c50 | 178 | |
Osamu Nakamura |
0:813a237f1c50 | 179 | if ((colour == 0x0000f0f0) || (colour == 0x0000fff4)) { |
Osamu Nakamura |
0:813a237f1c50 | 180 | str_draw_x = wk_x; |
Osamu Nakamura |
0:813a237f1c50 | 181 | str_draw_y = wk_y + wk_h + 1; |
Osamu Nakamura |
0:813a237f1c50 | 182 | } |
Osamu Nakamura |
0:813a237f1c50 | 183 | |
Osamu Nakamura |
0:813a237f1c50 | 184 | idx_base = (wk_x + (DISP_PIXEL_WIDTH * wk_y)) * RESULT_BUFFER_BYTE_PER_PIXEL; |
Osamu Nakamura |
0:813a237f1c50 | 185 | |
Osamu Nakamura |
0:813a237f1c50 | 186 | /* Select color */ |
Osamu Nakamura |
0:813a237f1c50 | 187 | coller_pix[0] = (colour >> 8) & 0xff; /* 4:Green 4:Blue */ |
Osamu Nakamura |
0:813a237f1c50 | 188 | coller_pix[1] = colour & 0xff; /* 4:Alpha 4:Red */ |
Osamu Nakamura |
0:813a237f1c50 | 189 | |
Osamu Nakamura |
0:813a237f1c50 | 190 | /* top */ |
Osamu Nakamura |
0:813a237f1c50 | 191 | if (t_draw) { |
Osamu Nakamura |
0:813a237f1c50 | 192 | wk_idx = idx_base; |
Osamu Nakamura |
0:813a237f1c50 | 193 | for (j = 0; j < wk_w; j++) { |
Osamu Nakamura |
0:813a237f1c50 | 194 | user_frame_buffer_result[wk_idx++] = coller_pix[0]; |
Osamu Nakamura |
0:813a237f1c50 | 195 | user_frame_buffer_result[wk_idx++] = coller_pix[1]; |
Osamu Nakamura |
0:813a237f1c50 | 196 | } |
Osamu Nakamura |
0:813a237f1c50 | 197 | } |
Osamu Nakamura |
0:813a237f1c50 | 198 | |
Osamu Nakamura |
0:813a237f1c50 | 199 | /* middle */ |
Osamu Nakamura |
0:813a237f1c50 | 200 | for (i = 1; i < (wk_h - 1); i++) { |
Osamu Nakamura |
0:813a237f1c50 | 201 | wk_idx = idx_base + (DISP_PIXEL_WIDTH * RESULT_BUFFER_BYTE_PER_PIXEL * i); |
Osamu Nakamura |
0:813a237f1c50 | 202 | if (l_draw) { |
Osamu Nakamura |
0:813a237f1c50 | 203 | user_frame_buffer_result[wk_idx + 0] = coller_pix[0]; |
Osamu Nakamura |
0:813a237f1c50 | 204 | user_frame_buffer_result[wk_idx + 1] = coller_pix[1]; |
Osamu Nakamura |
0:813a237f1c50 | 205 | } |
Osamu Nakamura |
0:813a237f1c50 | 206 | wk_idx += (wk_w - 1) * 2; |
Osamu Nakamura |
0:813a237f1c50 | 207 | if (r_draw) { |
Osamu Nakamura |
0:813a237f1c50 | 208 | user_frame_buffer_result[wk_idx + 0] = coller_pix[0]; |
Osamu Nakamura |
0:813a237f1c50 | 209 | user_frame_buffer_result[wk_idx + 1] = coller_pix[1]; |
Osamu Nakamura |
0:813a237f1c50 | 210 | } |
Osamu Nakamura |
0:813a237f1c50 | 211 | } |
Osamu Nakamura |
0:813a237f1c50 | 212 | |
Osamu Nakamura |
0:813a237f1c50 | 213 | /* bottom */ |
Osamu Nakamura |
0:813a237f1c50 | 214 | if (b_draw) { |
Osamu Nakamura |
0:813a237f1c50 | 215 | wk_idx = idx_base + (DISP_PIXEL_WIDTH * RESULT_BUFFER_BYTE_PER_PIXEL * (wk_h - 1)); |
Osamu Nakamura |
0:813a237f1c50 | 216 | for (j = 0; j < wk_w; j++) { |
Osamu Nakamura |
0:813a237f1c50 | 217 | user_frame_buffer_result[wk_idx++] = coller_pix[0]; |
Osamu Nakamura |
0:813a237f1c50 | 218 | user_frame_buffer_result[wk_idx++] = coller_pix[1]; |
Osamu Nakamura |
0:813a237f1c50 | 219 | } |
Osamu Nakamura |
0:813a237f1c50 | 220 | } |
Osamu Nakamura |
0:813a237f1c50 | 221 | } |
Osamu Nakamura |
0:813a237f1c50 | 222 | |
Osamu Nakamura |
0:813a237f1c50 | 223 | static void DrawString(const char * str, uint32_t const colour) { |
Osamu Nakamura |
0:813a237f1c50 | 224 | ascii_font.Erase(0x00000090, str_draw_x, str_draw_y, |
Osamu Nakamura |
0:813a237f1c50 | 225 | (AsciiFont::CHAR_PIX_WIDTH * strlen(str) + 2), |
Osamu Nakamura |
0:813a237f1c50 | 226 | (AsciiFont::CHAR_PIX_HEIGHT + 2)); |
Osamu Nakamura |
0:813a237f1c50 | 227 | ascii_font.DrawStr(str, str_draw_x + 1, str_draw_y + 1, colour, 1); |
Osamu Nakamura |
0:813a237f1c50 | 228 | str_draw_y += AsciiFont::CHAR_PIX_HEIGHT + 1; |
Osamu Nakamura |
0:813a237f1c50 | 229 | } |
Osamu Nakamura |
0:813a237f1c50 | 230 | |
Osamu Nakamura |
0:813a237f1c50 | 231 | static void button_fall(void) { |
Osamu Nakamura |
0:813a237f1c50 | 232 | if (imageNo_setting == HVC_EXECUTE_IMAGE_NONE) { |
Osamu Nakamura |
0:813a237f1c50 | 233 | imageNo_setting = HVC_EXECUTE_IMAGE_QVGA_HALF; |
Osamu Nakamura |
0:813a237f1c50 | 234 | } else if (imageNo_setting == HVC_EXECUTE_IMAGE_QVGA_HALF) { |
Osamu Nakamura |
0:813a237f1c50 | 235 | imageNo_setting = HVC_EXECUTE_IMAGE_QVGA; |
Osamu Nakamura |
0:813a237f1c50 | 236 | } else { |
Osamu Nakamura |
0:813a237f1c50 | 237 | imageNo_setting = HVC_EXECUTE_IMAGE_NONE; |
Osamu Nakamura |
0:813a237f1c50 | 238 | } |
Osamu Nakamura |
0:813a237f1c50 | 239 | } |
Osamu Nakamura |
0:813a237f1c50 | 240 | |
Osamu Nakamura |
0:813a237f1c50 | 241 | void init_recognition_layers(DisplayBase * p_display) { |
Osamu Nakamura |
0:813a237f1c50 | 242 | DisplayBase::rect_t rect; |
Osamu Nakamura |
0:813a237f1c50 | 243 | |
Osamu Nakamura |
0:813a237f1c50 | 244 | /* The layer by which the image is drawn */ |
Osamu Nakamura |
0:813a237f1c50 | 245 | rect.vs = 0; |
Osamu Nakamura |
0:813a237f1c50 | 246 | rect.vw = DISP_PIXEL_HEIGHT; |
Osamu Nakamura |
0:813a237f1c50 | 247 | rect.hs = 0; |
Osamu Nakamura |
0:813a237f1c50 | 248 | rect.hw = DISP_PIXEL_WIDTH; |
Osamu Nakamura |
0:813a237f1c50 | 249 | p_display->Graphics_Read_Setting( |
Osamu Nakamura |
0:813a237f1c50 | 250 | DisplayBase::GRAPHICS_LAYER_0, |
Osamu Nakamura |
0:813a237f1c50 | 251 | (void *)user_frame_buffer0, |
Osamu Nakamura |
0:813a237f1c50 | 252 | FRAME_BUFFER_STRIDE, |
Osamu Nakamura |
0:813a237f1c50 | 253 | DisplayBase::GRAPHICS_FORMAT_YCBCR422, |
Osamu Nakamura |
0:813a237f1c50 | 254 | DisplayBase::WR_RD_WRSWA_32_16BIT, |
Osamu Nakamura |
0:813a237f1c50 | 255 | &rect |
Osamu Nakamura |
0:813a237f1c50 | 256 | ); |
Osamu Nakamura |
0:813a237f1c50 | 257 | p_display->Graphics_Start(DisplayBase::GRAPHICS_LAYER_0); |
Osamu Nakamura |
0:813a237f1c50 | 258 | |
Osamu Nakamura |
0:813a237f1c50 | 259 | /* The layer by which the image recognition is drawn */ |
Osamu Nakamura |
0:813a237f1c50 | 260 | rect.vs = 0; |
Osamu Nakamura |
0:813a237f1c50 | 261 | rect.vw = LCD_PIXEL_HEIGHT; |
Osamu Nakamura |
0:813a237f1c50 | 262 | rect.hs = 0; |
Osamu Nakamura |
0:813a237f1c50 | 263 | rect.hw = DISP_PIXEL_WIDTH; |
Osamu Nakamura |
0:813a237f1c50 | 264 | p_display->Graphics_Read_Setting( |
Osamu Nakamura |
0:813a237f1c50 | 265 | DisplayBase::GRAPHICS_LAYER_1, |
Osamu Nakamura |
0:813a237f1c50 | 266 | (void *)user_frame_buffer_result, |
Osamu Nakamura |
0:813a237f1c50 | 267 | RESULT_BUFFER_STRIDE, |
Osamu Nakamura |
0:813a237f1c50 | 268 | DisplayBase::GRAPHICS_FORMAT_ARGB4444, |
Osamu Nakamura |
0:813a237f1c50 | 269 | DisplayBase::WR_RD_WRSWA_32_16BIT, |
Osamu Nakamura |
0:813a237f1c50 | 270 | &rect |
Osamu Nakamura |
0:813a237f1c50 | 271 | ); |
Osamu Nakamura |
0:813a237f1c50 | 272 | p_display->Graphics_Start(DisplayBase::GRAPHICS_LAYER_1); |
Osamu Nakamura |
0:813a237f1c50 | 273 | } |
Osamu Nakamura |
0:813a237f1c50 | 274 | |
Osamu Nakamura |
0:813a237f1c50 | 275 | void recognition_task(DisplayBase * p_display) { |
Osamu Nakamura |
0:813a237f1c50 | 276 | INT32 ret = 0; |
Osamu Nakamura |
0:813a237f1c50 | 277 | UINT8 status; |
Osamu Nakamura |
0:813a237f1c50 | 278 | HVC_VERSION version; |
Osamu Nakamura |
0:813a237f1c50 | 279 | HVC_RESULT *pHVCResult = NULL; |
Osamu Nakamura |
0:813a237f1c50 | 280 | HVC_IMAGE *pImage = NULL; |
Osamu Nakamura |
0:813a237f1c50 | 281 | INT32 execFlag; |
Osamu Nakamura |
0:813a237f1c50 | 282 | INT32 imageNo; |
Osamu Nakamura |
0:813a237f1c50 | 283 | INT32 userID; |
Osamu Nakamura |
0:813a237f1c50 | 284 | INT32 next_userID; |
Osamu Nakamura |
0:813a237f1c50 | 285 | INT32 dataID; |
Osamu Nakamura |
0:813a237f1c50 | 286 | const char *pExStr[] = {"?", "Neutral", "Happiness", "Surprise", "Anger", "Sadness"}; |
Osamu Nakamura |
0:813a237f1c50 | 287 | uint32_t i; |
Osamu Nakamura |
0:813a237f1c50 | 288 | char Str_disp[32]; |
Osamu Nakamura |
0:813a237f1c50 | 289 | Timer resp_time; |
Osamu Nakamura |
0:813a237f1c50 | 290 | |
Osamu Nakamura |
0:813a237f1c50 | 291 | /* Register the button */ |
Osamu Nakamura |
0:813a237f1c50 | 292 | button.fall(&button_fall); |
Osamu Nakamura |
0:813a237f1c50 | 293 | |
Osamu Nakamura |
0:813a237f1c50 | 294 | /* Initializing Recognition layers */ |
Osamu Nakamura |
0:813a237f1c50 | 295 | EraseImage(); |
Osamu Nakamura |
0:813a237f1c50 | 296 | memset(user_frame_buffer_result, 0, sizeof(user_frame_buffer_result)); |
Osamu Nakamura |
0:813a237f1c50 | 297 | init_recognition_layers(p_display); |
Osamu Nakamura |
0:813a237f1c50 | 298 | |
Osamu Nakamura |
0:813a237f1c50 | 299 | /* Result Structure Allocation */ |
Osamu Nakamura |
0:813a237f1c50 | 300 | pHVCResult = (HVC_RESULT *)malloc(sizeof(HVC_RESULT)); |
Osamu Nakamura |
0:813a237f1c50 | 301 | if (pHVCResult == NULL) { |
Osamu Nakamura |
0:813a237f1c50 | 302 | printf("Memory Allocation Error : %08x\n", sizeof(HVC_RESULT)); |
Osamu Nakamura |
0:813a237f1c50 | 303 | mbed_die(); |
Osamu Nakamura |
0:813a237f1c50 | 304 | } |
Osamu Nakamura |
0:813a237f1c50 | 305 | |
Osamu Nakamura |
0:813a237f1c50 | 306 | /* Image Structure allocation */ |
Osamu Nakamura |
0:813a237f1c50 | 307 | pImage = (HVC_IMAGE *)malloc(sizeof(HVC_IMAGE)); |
Osamu Nakamura |
0:813a237f1c50 | 308 | if (pImage == NULL) { |
Osamu Nakamura |
0:813a237f1c50 | 309 | printf("Memory Allocation Error : %08x\n", sizeof(HVC_RESULT)); |
Osamu Nakamura |
0:813a237f1c50 | 310 | mbed_die(); |
Osamu Nakamura |
0:813a237f1c50 | 311 | } |
Osamu Nakamura |
0:813a237f1c50 | 312 | |
Osamu Nakamura |
0:813a237f1c50 | 313 | while (1) { |
Osamu Nakamura |
0:813a237f1c50 | 314 | /* try to connect a serial device */ |
Osamu Nakamura |
0:813a237f1c50 | 315 | while (!serial.connect()) { |
Osamu Nakamura |
0:813a237f1c50 | 316 | Thread::wait(500); |
Osamu Nakamura |
0:813a237f1c50 | 317 | } |
Osamu Nakamura |
0:813a237f1c50 | 318 | serial.baud(921600); |
Osamu Nakamura |
0:813a237f1c50 | 319 | setting_req = true; |
Osamu Nakamura |
0:813a237f1c50 | 320 | |
Osamu Nakamura |
0:813a237f1c50 | 321 | do { |
Osamu Nakamura |
0:813a237f1c50 | 322 | /* Initializing variables */ |
Osamu Nakamura |
0:813a237f1c50 | 323 | next_userID = 0; |
Osamu Nakamura |
0:813a237f1c50 | 324 | dataID = 0; |
Osamu Nakamura |
0:813a237f1c50 | 325 | |
Osamu Nakamura |
0:813a237f1c50 | 326 | /* Get Model and Version */ |
Osamu Nakamura |
0:813a237f1c50 | 327 | ret = HVC_GetVersion(UART_SETTING_TIMEOUT, &version, &status); |
Osamu Nakamura |
0:813a237f1c50 | 328 | if ((ret != 0) || (status != 0)) { |
Osamu Nakamura |
0:813a237f1c50 | 329 | break; |
Osamu Nakamura |
0:813a237f1c50 | 330 | } |
Osamu Nakamura |
0:813a237f1c50 | 331 | |
Osamu Nakamura |
0:813a237f1c50 | 332 | while (1) { |
Osamu Nakamura |
0:813a237f1c50 | 333 | if (!serial.connected()) { |
Osamu Nakamura |
0:813a237f1c50 | 334 | break; |
Osamu Nakamura |
0:813a237f1c50 | 335 | } |
Osamu Nakamura |
0:813a237f1c50 | 336 | |
Osamu Nakamura |
0:813a237f1c50 | 337 | /* Execute Setting */ |
Osamu Nakamura |
0:813a237f1c50 | 338 | if (setting_req) { |
Osamu Nakamura |
0:813a237f1c50 | 339 | setting_req = false; |
Osamu Nakamura |
0:813a237f1c50 | 340 | /* Set Camera Angle */ |
Osamu Nakamura |
0:813a237f1c50 | 341 | ret = HVC_SetCameraAngle(UART_SETTING_TIMEOUT, SENSOR_ROLL_ANGLE_DEFAULT, &status); |
Osamu Nakamura |
0:813a237f1c50 | 342 | if ((ret != 0) || (status != 0)) { |
Osamu Nakamura |
0:813a237f1c50 | 343 | break; |
Osamu Nakamura |
0:813a237f1c50 | 344 | } |
Osamu Nakamura |
0:813a237f1c50 | 345 | /* Set Threshold Values */ |
Osamu Nakamura |
0:813a237f1c50 | 346 | ret = HVC_SetThreshold(UART_SETTING_TIMEOUT, &setting.threshold, &status); |
Osamu Nakamura |
0:813a237f1c50 | 347 | if ((ret != 0) || (status != 0)) { |
Osamu Nakamura |
0:813a237f1c50 | 348 | break; |
Osamu Nakamura |
0:813a237f1c50 | 349 | } |
Osamu Nakamura |
0:813a237f1c50 | 350 | ret = HVC_GetThreshold(UART_SETTING_TIMEOUT, &setting.threshold, &status); |
Osamu Nakamura |
0:813a237f1c50 | 351 | if ((ret != 0) || (status != 0)) { |
Osamu Nakamura |
0:813a237f1c50 | 352 | break; |
Osamu Nakamura |
0:813a237f1c50 | 353 | } |
Osamu Nakamura |
0:813a237f1c50 | 354 | /* Set Detection Size */ |
Osamu Nakamura |
0:813a237f1c50 | 355 | ret = HVC_SetSizeRange(UART_SETTING_TIMEOUT, &setting.sizeRange, &status); |
Osamu Nakamura |
0:813a237f1c50 | 356 | if ((ret != 0) || (status != 0)) { |
Osamu Nakamura |
0:813a237f1c50 | 357 | break; |
Osamu Nakamura |
0:813a237f1c50 | 358 | } |
Osamu Nakamura |
0:813a237f1c50 | 359 | ret = HVC_GetSizeRange(UART_SETTING_TIMEOUT, &setting.sizeRange, &status); |
Osamu Nakamura |
0:813a237f1c50 | 360 | if ((ret != 0) || (status != 0)) { |
Osamu Nakamura |
0:813a237f1c50 | 361 | break; |
Osamu Nakamura |
0:813a237f1c50 | 362 | } |
Osamu Nakamura |
0:813a237f1c50 | 363 | /* Set Face Angle */ |
Osamu Nakamura |
0:813a237f1c50 | 364 | ret = HVC_SetFaceDetectionAngle(UART_SETTING_TIMEOUT, setting.pose, setting.angle, &status); |
Osamu Nakamura |
0:813a237f1c50 | 365 | if ((ret != 0) || (status != 0)) { |
Osamu Nakamura |
0:813a237f1c50 | 366 | break; |
Osamu Nakamura |
0:813a237f1c50 | 367 | } |
Osamu Nakamura |
0:813a237f1c50 | 368 | ret = HVC_GetFaceDetectionAngle(UART_SETTING_TIMEOUT, &setting.pose, &setting.angle, &status); |
Osamu Nakamura |
0:813a237f1c50 | 369 | if ((ret != 0) || (status != 0)) { |
Osamu Nakamura |
0:813a237f1c50 | 370 | break; |
Osamu Nakamura |
0:813a237f1c50 | 371 | } |
Osamu Nakamura |
0:813a237f1c50 | 372 | } |
Osamu Nakamura |
0:813a237f1c50 | 373 | |
Osamu Nakamura |
0:813a237f1c50 | 374 | /* Execute Registration */ |
Osamu Nakamura |
0:813a237f1c50 | 375 | if (registrationr_req) { |
Osamu Nakamura |
0:813a237f1c50 | 376 | int wk_width; |
Osamu Nakamura |
0:813a237f1c50 | 377 | |
Osamu Nakamura |
0:813a237f1c50 | 378 | if ((pHVCResult->fdResult.num == 1) && (pHVCResult->fdResult.fcResult[0].recognitionResult.uid >= 0)) { |
Osamu Nakamura |
0:813a237f1c50 | 379 | userID = pHVCResult->fdResult.fcResult[0].recognitionResult.uid; |
Osamu Nakamura |
0:813a237f1c50 | 380 | } else { |
Osamu Nakamura |
0:813a237f1c50 | 381 | userID = next_userID; |
Osamu Nakamura |
0:813a237f1c50 | 382 | } |
Osamu Nakamura |
0:813a237f1c50 | 383 | ret = HVC_Registration(UART_REGIST_EXECUTE_TIMEOUT, userID, dataID, pImage, &status); |
Osamu Nakamura |
0:813a237f1c50 | 384 | if ((ret == 0) && (status == 0)) { |
Osamu Nakamura |
0:813a237f1c50 | 385 | if (userID == next_userID) { |
Osamu Nakamura |
0:813a237f1c50 | 386 | next_userID++; |
Osamu Nakamura |
0:813a237f1c50 | 387 | if (next_userID >= USER_ID_NUM_MAX) { |
Osamu Nakamura |
0:813a237f1c50 | 388 | next_userID = 0; |
Osamu Nakamura |
0:813a237f1c50 | 389 | } |
Osamu Nakamura |
0:813a237f1c50 | 390 | } |
Osamu Nakamura |
0:813a237f1c50 | 391 | memset(user_frame_buffer_result, 0, sizeof(user_frame_buffer_result)); |
Osamu Nakamura |
0:813a237f1c50 | 392 | DrawImage(128, 88, pImage->width, pImage->height, pImage->image, 1); |
Osamu Nakamura |
0:813a237f1c50 | 393 | memset(Str_disp, 0, sizeof(Str_disp)); |
Osamu Nakamura |
0:813a237f1c50 | 394 | sprintf(Str_disp, "USER%03d", userID + 1); |
Osamu Nakamura |
0:813a237f1c50 | 395 | wk_width = (AsciiFont::CHAR_PIX_WIDTH * strlen(Str_disp)) + 2; |
Osamu Nakamura |
0:813a237f1c50 | 396 | ascii_font.Erase(0x00000090, (DISP_PIXEL_WIDTH - wk_width) / 2, 153, wk_width, (AsciiFont::CHAR_PIX_HEIGHT + 2)); |
Osamu Nakamura |
0:813a237f1c50 | 397 | ascii_font.DrawStr(Str_disp, (DISP_PIXEL_WIDTH - wk_width) / 2 + 1, 154, 0x0000ffff, 1); |
Osamu Nakamura |
0:813a237f1c50 | 398 | Thread::wait(1200); |
Osamu Nakamura |
0:813a237f1c50 | 399 | } else { |
Osamu Nakamura |
0:813a237f1c50 | 400 | if (status == 0x02) { |
Osamu Nakamura |
0:813a237f1c50 | 401 | wk_width = (AsciiFont::CHAR_PIX_WIDTH * (sizeof(ERROR_02) - 1)) + 4; |
Osamu Nakamura |
0:813a237f1c50 | 402 | ascii_font.Erase(0x00000090, (DISP_PIXEL_WIDTH - wk_width) / 2, 120, wk_width, (AsciiFont::CHAR_PIX_HEIGHT + 3)); |
Osamu Nakamura |
0:813a237f1c50 | 403 | ascii_font.DrawStr(ERROR_02, (DISP_PIXEL_WIDTH - wk_width) / 2 + 2, 121, 0x0000ffff, 1); |
Osamu Nakamura |
0:813a237f1c50 | 404 | Thread::wait(1500); |
Osamu Nakamura |
0:813a237f1c50 | 405 | } |
Osamu Nakamura |
0:813a237f1c50 | 406 | } |
Osamu Nakamura |
0:813a237f1c50 | 407 | registrationr_req = false; |
Osamu Nakamura |
0:813a237f1c50 | 408 | } |
Osamu Nakamura |
0:813a237f1c50 | 409 | |
Osamu Nakamura |
0:813a237f1c50 | 410 | /* Execute Detection */ |
Osamu Nakamura |
0:813a237f1c50 | 411 | |
Osamu Nakamura |
0:813a237f1c50 | 412 | semaphore_wait_ret = iot_ready_semaphore.wait(); |
Osamu Nakamura |
0:813a237f1c50 | 413 | if(semaphore_wait_ret == -1) |
Osamu Nakamura |
0:813a237f1c50 | 414 | { |
Osamu Nakamura |
0:813a237f1c50 | 415 | printf("<recog_proc> semaphore error.\n"); |
Osamu Nakamura |
0:813a237f1c50 | 416 | }else{ |
Osamu Nakamura |
0:813a237f1c50 | 417 | execFlag = setting.execFlag; |
Osamu Nakamura |
0:813a237f1c50 | 418 | if ((execFlag & HVC_ACTIV_FACE_DETECTION) == 0) { |
Osamu Nakamura |
0:813a237f1c50 | 419 | execFlag &= ~(HVC_ACTIV_AGE_ESTIMATION | HVC_ACTIV_GENDER_ESTIMATION | HVC_ACTIV_EXPRESSION_ESTIMATION); |
Osamu Nakamura |
0:813a237f1c50 | 420 | } |
Osamu Nakamura |
0:813a237f1c50 | 421 | imageNo = imageNo_setting; |
Osamu Nakamura |
0:813a237f1c50 | 422 | resp_time.reset(); |
Osamu Nakamura |
0:813a237f1c50 | 423 | resp_time.start(); |
Osamu Nakamura |
0:813a237f1c50 | 424 | ret = HVC_ExecuteEx(UART_EXECUTE_TIMEOUT, execFlag, imageNo, pHVCResult, &status); |
Osamu Nakamura |
0:813a237f1c50 | 425 | resp_time.stop(); |
Osamu Nakamura |
0:813a237f1c50 | 426 | if ((ret == 0) && (status == 0)) { |
Osamu Nakamura |
0:813a237f1c50 | 427 | if (imageNo == HVC_EXECUTE_IMAGE_QVGA_HALF) { |
Osamu Nakamura |
0:813a237f1c50 | 428 | DrawImage(0, 0, pHVCResult->image.width, pHVCResult->image.height, pHVCResult->image.image, 2); |
Osamu Nakamura |
0:813a237f1c50 | 429 | } else if (imageNo == HVC_EXECUTE_IMAGE_QVGA) { |
Osamu Nakamura |
0:813a237f1c50 | 430 | DrawImage(0, 0, pHVCResult->image.width, pHVCResult->image.height, pHVCResult->image.image, 1); |
Osamu Nakamura |
0:813a237f1c50 | 431 | } else { |
Osamu Nakamura |
0:813a237f1c50 | 432 | EraseImage(); |
Osamu Nakamura |
0:813a237f1c50 | 433 | } |
Osamu Nakamura |
0:813a237f1c50 | 434 | memset(user_frame_buffer_result, 0, sizeof(user_frame_buffer_result)); |
Osamu Nakamura |
0:813a237f1c50 | 435 | |
Osamu Nakamura |
0:813a237f1c50 | 436 | if (pHVCResult->executedFunc & HVC_ACTIV_BODY_DETECTION) { |
Osamu Nakamura |
0:813a237f1c50 | 437 | /* Body Detection result */ |
Osamu Nakamura |
0:813a237f1c50 | 438 | result_hvcp2_bd_cnt = pHVCResult->bdResult.num; |
Osamu Nakamura |
0:813a237f1c50 | 439 | for (i = 0; i < pHVCResult->bdResult.num; i++) { |
Osamu Nakamura |
0:813a237f1c50 | 440 | DrawSquare(pHVCResult->bdResult.bdResult[i].posX, |
Osamu Nakamura |
0:813a237f1c50 | 441 | pHVCResult->bdResult.bdResult[i].posY, |
Osamu Nakamura |
0:813a237f1c50 | 442 | pHVCResult->bdResult.bdResult[i].size, |
Osamu Nakamura |
0:813a237f1c50 | 443 | 0x000000ff); |
Osamu Nakamura |
0:813a237f1c50 | 444 | result_hvcp2_bd[i].body_rectangle.MinX = pHVCResult->bdResult.bdResult[i].posX; |
Osamu Nakamura |
0:813a237f1c50 | 445 | result_hvcp2_bd[i].body_rectangle.MinY = pHVCResult->bdResult.bdResult[i].posY; |
Osamu Nakamura |
0:813a237f1c50 | 446 | result_hvcp2_bd[i].body_rectangle.Width = pHVCResult->bdResult.bdResult[i].size; |
Osamu Nakamura |
0:813a237f1c50 | 447 | result_hvcp2_bd[i].body_rectangle.Height = pHVCResult->bdResult.bdResult[i].size; |
Osamu Nakamura |
0:813a237f1c50 | 448 | } |
Osamu Nakamura |
0:813a237f1c50 | 449 | } |
Osamu Nakamura |
0:813a237f1c50 | 450 | |
Osamu Nakamura |
0:813a237f1c50 | 451 | /* Face Detection result */ |
Osamu Nakamura |
0:813a237f1c50 | 452 | if (pHVCResult->executedFunc & |
Osamu Nakamura |
0:813a237f1c50 | 453 | (HVC_ACTIV_FACE_DETECTION | HVC_ACTIV_FACE_DIRECTION | |
Osamu Nakamura |
0:813a237f1c50 | 454 | HVC_ACTIV_AGE_ESTIMATION | HVC_ACTIV_GENDER_ESTIMATION | |
Osamu Nakamura |
0:813a237f1c50 | 455 | HVC_ACTIV_GAZE_ESTIMATION | HVC_ACTIV_BLINK_ESTIMATION | |
Osamu Nakamura |
0:813a237f1c50 | 456 | HVC_ACTIV_EXPRESSION_ESTIMATION | HVC_ACTIV_FACE_RECOGNITION)){ |
Osamu Nakamura |
0:813a237f1c50 | 457 | /* Face Detection result */ |
Osamu Nakamura |
0:813a237f1c50 | 458 | result_hvcp2_fd_cnt = pHVCResult->fdResult.num; |
Osamu Nakamura |
0:813a237f1c50 | 459 | for (i = 0; i < pHVCResult->fdResult.num; i++) { |
Osamu Nakamura |
0:813a237f1c50 | 460 | if (pHVCResult->executedFunc & HVC_ACTIV_FACE_DETECTION) { |
Osamu Nakamura |
0:813a237f1c50 | 461 | uint32_t detection_colour = 0x0000f0f0; /* green */ |
Osamu Nakamura |
0:813a237f1c50 | 462 | if (pHVCResult->executedFunc & HVC_ACTIV_FACE_RECOGNITION) { |
Osamu Nakamura |
0:813a237f1c50 | 463 | if (pHVCResult->fdResult.fcResult[i].recognitionResult.uid >= 0) { |
Osamu Nakamura |
0:813a237f1c50 | 464 | detection_colour = 0x0000fff4; /* blue */ |
Osamu Nakamura |
0:813a237f1c50 | 465 | } |
Osamu Nakamura |
0:813a237f1c50 | 466 | } |
Osamu Nakamura |
0:813a237f1c50 | 467 | /* Detection */ |
Osamu Nakamura |
0:813a237f1c50 | 468 | DrawSquare(pHVCResult->fdResult.fcResult[i].dtResult.posX, |
Osamu Nakamura |
0:813a237f1c50 | 469 | pHVCResult->fdResult.fcResult[i].dtResult.posY, |
Osamu Nakamura |
0:813a237f1c50 | 470 | pHVCResult->fdResult.fcResult[i].dtResult.size, |
Osamu Nakamura |
0:813a237f1c50 | 471 | detection_colour); |
Osamu Nakamura |
0:813a237f1c50 | 472 | |
Osamu Nakamura |
0:813a237f1c50 | 473 | result_hvcp2_fd[i].face_rectangle.MinX = pHVCResult->fdResult.fcResult[i].dtResult.posX; |
Osamu Nakamura |
0:813a237f1c50 | 474 | result_hvcp2_fd[i].face_rectangle.MinY = pHVCResult->fdResult.fcResult[i].dtResult.posY; |
Osamu Nakamura |
0:813a237f1c50 | 475 | result_hvcp2_fd[i].face_rectangle.Width = pHVCResult->fdResult.fcResult[i].dtResult.size; |
Osamu Nakamura |
0:813a237f1c50 | 476 | result_hvcp2_fd[i].face_rectangle.Height = pHVCResult->fdResult.fcResult[i].dtResult.size; |
Osamu Nakamura |
0:813a237f1c50 | 477 | } |
Osamu Nakamura |
0:813a237f1c50 | 478 | if (pHVCResult->executedFunc & HVC_ACTIV_FACE_RECOGNITION) { |
Osamu Nakamura |
0:813a237f1c50 | 479 | /* Recognition */ |
Osamu Nakamura |
0:813a237f1c50 | 480 | if (-128 == pHVCResult->fdResult.fcResult[i].recognitionResult.uid) { |
Osamu Nakamura |
0:813a237f1c50 | 481 | DrawString("Not possible", 0x0000f0ff); |
Osamu Nakamura |
0:813a237f1c50 | 482 | } else if (pHVCResult->fdResult.fcResult[i].recognitionResult.uid < 0) { |
Osamu Nakamura |
0:813a237f1c50 | 483 | DrawString("Not registered", 0x0000f0ff); |
Osamu Nakamura |
0:813a237f1c50 | 484 | } else { |
Osamu Nakamura |
0:813a237f1c50 | 485 | memset(Str_disp, 0, sizeof(Str_disp)); |
Osamu Nakamura |
0:813a237f1c50 | 486 | sprintf(Str_disp, "USER%03d", pHVCResult->fdResult.fcResult[i].recognitionResult.uid + 1); |
Osamu Nakamura |
0:813a237f1c50 | 487 | DrawString(Str_disp, 0x0000f0ff); |
Osamu Nakamura |
0:813a237f1c50 | 488 | } |
Osamu Nakamura |
0:813a237f1c50 | 489 | } |
Osamu Nakamura |
0:813a237f1c50 | 490 | if (pHVCResult->executedFunc & HVC_ACTIV_AGE_ESTIMATION) { |
Osamu Nakamura |
0:813a237f1c50 | 491 | /* Age */ |
Osamu Nakamura |
0:813a237f1c50 | 492 | if (-128 != pHVCResult->fdResult.fcResult[i].ageResult.age) { |
Osamu Nakamura |
0:813a237f1c50 | 493 | memset(Str_disp, 0, sizeof(Str_disp)); |
Osamu Nakamura |
0:813a237f1c50 | 494 | sprintf(Str_disp, "Age:%d", pHVCResult->fdResult.fcResult[i].ageResult.age); |
Osamu Nakamura |
0:813a237f1c50 | 495 | DrawString(Str_disp, 0x0000f0ff); |
Osamu Nakamura |
0:813a237f1c50 | 496 | } |
Osamu Nakamura |
0:813a237f1c50 | 497 | } |
Osamu Nakamura |
0:813a237f1c50 | 498 | if (pHVCResult->executedFunc & HVC_ACTIV_GENDER_ESTIMATION) { |
Osamu Nakamura |
0:813a237f1c50 | 499 | /* Gender */ |
Osamu Nakamura |
0:813a237f1c50 | 500 | if (-128 != pHVCResult->fdResult.fcResult[i].genderResult.gender) { |
Osamu Nakamura |
0:813a237f1c50 | 501 | if (1 == pHVCResult->fdResult.fcResult[i].genderResult.gender) { |
Osamu Nakamura |
0:813a237f1c50 | 502 | DrawString("Male", 0x0000fff4); |
Osamu Nakamura |
0:813a237f1c50 | 503 | } else { |
Osamu Nakamura |
0:813a237f1c50 | 504 | DrawString("Female", 0x00006dff); |
Osamu Nakamura |
0:813a237f1c50 | 505 | } |
Osamu Nakamura |
0:813a237f1c50 | 506 | } |
Osamu Nakamura |
0:813a237f1c50 | 507 | } |
Osamu Nakamura |
0:813a237f1c50 | 508 | if (pHVCResult->executedFunc & HVC_ACTIV_EXPRESSION_ESTIMATION) { |
Osamu Nakamura |
0:813a237f1c50 | 509 | /* Expression */ |
Osamu Nakamura |
0:813a237f1c50 | 510 | if (-128 != pHVCResult->fdResult.fcResult[i].expressionResult.score[0]) { |
Osamu Nakamura |
0:813a237f1c50 | 511 | uint32_t colour; |
Osamu Nakamura |
0:813a237f1c50 | 512 | |
Osamu Nakamura |
0:813a237f1c50 | 513 | result_hvcp2_fd[i].scores.score_neutral = pHVCResult->fdResult.fcResult[i].expressionResult.score[0]; |
Osamu Nakamura |
0:813a237f1c50 | 514 | result_hvcp2_fd[i].scores.score_anger = pHVCResult->fdResult.fcResult[i].expressionResult.score[1]; |
Osamu Nakamura |
0:813a237f1c50 | 515 | result_hvcp2_fd[i].scores.score_happiness = pHVCResult->fdResult.fcResult[i].expressionResult.score[2]; |
Osamu Nakamura |
0:813a237f1c50 | 516 | result_hvcp2_fd[i].scores.score_surprise = pHVCResult->fdResult.fcResult[i].expressionResult.score[3]; |
Osamu Nakamura |
0:813a237f1c50 | 517 | result_hvcp2_fd[i].scores.score_sadness = pHVCResult->fdResult.fcResult[i].expressionResult.score[4]; |
Osamu Nakamura |
0:813a237f1c50 | 518 | result_hvcp2_fd[i].age.age = pHVCResult->fdResult.fcResult[i].ageResult.age; |
Osamu Nakamura |
0:813a237f1c50 | 519 | result_hvcp2_fd[i].gender.gender = pHVCResult->fdResult.fcResult[i].genderResult.gender; |
Osamu Nakamura |
0:813a237f1c50 | 520 | |
Osamu Nakamura |
0:813a237f1c50 | 521 | if (pHVCResult->fdResult.fcResult[i].expressionResult.topExpression > EX_SADNESS) { |
Osamu Nakamura |
0:813a237f1c50 | 522 | pHVCResult->fdResult.fcResult[i].expressionResult.topExpression = 0; |
Osamu Nakamura |
0:813a237f1c50 | 523 | } |
Osamu Nakamura |
0:813a237f1c50 | 524 | switch (pHVCResult->fdResult.fcResult[i].expressionResult.topExpression) { |
Osamu Nakamura |
0:813a237f1c50 | 525 | case 1: colour = 0x0000ffff; break; /* white */ |
Osamu Nakamura |
0:813a237f1c50 | 526 | case 2: colour = 0x0000f0ff; break; /* yellow */ |
Osamu Nakamura |
0:813a237f1c50 | 527 | case 3: colour = 0x000060ff; break; /* orange */ |
Osamu Nakamura |
0:813a237f1c50 | 528 | case 4: colour = 0x00000fff; break; /* purple */ |
Osamu Nakamura |
0:813a237f1c50 | 529 | case 5: colour = 0x0000fff4; break; /* blue */ |
Osamu Nakamura |
0:813a237f1c50 | 530 | default: colour = 0x0000ffff; break; /* white */ |
Osamu Nakamura |
0:813a237f1c50 | 531 | } |
Osamu Nakamura |
0:813a237f1c50 | 532 | DrawString(pExStr[pHVCResult->fdResult.fcResult[i].expressionResult.topExpression], colour); |
Osamu Nakamura |
0:813a237f1c50 | 533 | } |
Osamu Nakamura |
0:813a237f1c50 | 534 | } |
Osamu Nakamura |
0:813a237f1c50 | 535 | } |
Osamu Nakamura |
0:813a237f1c50 | 536 | } |
Osamu Nakamura |
0:813a237f1c50 | 537 | } |
Osamu Nakamura |
0:813a237f1c50 | 538 | iot_ready_semaphore.release(); |
Osamu Nakamura |
0:813a237f1c50 | 539 | } |
Osamu Nakamura |
0:813a237f1c50 | 540 | |
Osamu Nakamura |
0:813a237f1c50 | 541 | /* Response time */ |
Osamu Nakamura |
0:813a237f1c50 | 542 | memset(Str_disp, 0, sizeof(Str_disp)); |
Osamu Nakamura |
0:813a237f1c50 | 543 | sprintf(Str_disp, "Response time:%dms", resp_time.read_ms()); |
Osamu Nakamura |
0:813a237f1c50 | 544 | ascii_font.Erase(0, 0, 0, 0, 0); |
Osamu Nakamura |
0:813a237f1c50 | 545 | ascii_font.DrawStr(Str_disp, 0, LCD_PIXEL_HEIGHT - AsciiFont::CHAR_PIX_HEIGHT, 0x0000ffff, 1); |
Osamu Nakamura |
0:813a237f1c50 | 546 | } |
Osamu Nakamura |
0:813a237f1c50 | 547 | } while(0); |
Osamu Nakamura |
0:813a237f1c50 | 548 | |
Osamu Nakamura |
0:813a237f1c50 | 549 | EraseImage(); |
Osamu Nakamura |
0:813a237f1c50 | 550 | memset(user_frame_buffer_result, 0, sizeof(user_frame_buffer_result)); |
Osamu Nakamura |
0:813a237f1c50 | 551 | } |
Osamu Nakamura |
0:813a237f1c50 | 552 | } |
Osamu Nakamura |
0:813a237f1c50 | 553 |