1-
21/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
32
43Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,16 +12,17 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1312See the License for the specific language governing permissions and
1413limitations under the License.
1514==============================================================================*/
16- #include < cstdlib>
17- #include < cstring>
18- #include < iostream>
1915
16+ #include " string.h"
2017#include " freertos/FreeRTOS.h"
2118#include " freertos/task.h"
19+
20+ #if (CONFIG_TFLITE_USE_BSP)
21+ #include " bsp/esp-bsp.h"
22+ #endif
23+
24+ #include " esp_heap_caps.h"
2225#include " esp_log.h"
23- #include " esp_spi_flash.h"
24- #include " esp_system.h"
25- #include " esp_timer.h"
2626
2727#include " app_camera_esp.h"
2828#include " esp_camera.h"
@@ -31,8 +31,7 @@ limitations under the License.
3131#include " esp_main.h"
3232
3333static const char * TAG = " app_camera" ;
34-
35- static uint16_t *display_buf; // buffer to hold data to be sent to display
34+ static uint16_t * display_buf;
3635
3736// Get the camera module ready
3837TfLiteStatus InitCamera () {
@@ -84,13 +83,19 @@ TfLiteStatus GetImage(int image_width, int image_height, int channels, int8_t* i
8483 // In case if display support is enabled, we initialise camera in rgb mode
8584 // Hence, we need to convert this data to grayscale to send it to tf model
8685 // For display we extra-polate the data to 192X192
86+
87+ // point to the last quarter of buffer
88+ uint16_t * cam_buf = display_buf + (96 * 96 * 3 );
89+ memcpy ((uint8_t *)cam_buf, fb->buf , fb->len );
90+ esp_camera_fb_return (fb);
91+
8792 for (int i = 0 ; i < kNumRows ; i++) {
8893 for (int j = 0 ; j < kNumCols ; j++) {
89- uint16_t pixel = (( uint16_t *) (fb-> buf )) [i * kNumCols + j];
94+ uint16_t inference_pixel = cam_buf [i * kNumCols + j];
9095
9196 // for inference
92- uint8_t hb = pixel & 0xFF ;
93- uint8_t lb = pixel >> 8 ;
97+ uint8_t hb = inference_pixel & 0xFF ;
98+ uint8_t lb = inference_pixel >> 8 ;
9499 uint8_t r = (lb & 0x1F ) << 3 ;
95100 uint8_t g = ((hb & 0x07 ) << 5 ) | ((lb & 0xE0 ) >> 3 );
96101 uint8_t b = (hb & 0xF8 );
@@ -102,8 +107,14 @@ TfLiteStatus GetImage(int image_width, int image_height, int channels, int8_t* i
102107 int8_t grey_pixel = ((305 * r + 600 * g + 119 * b) >> 10 ) - 128 ;
103108
104109 image_data[i * kNumCols + j] = grey_pixel;
110+ }
111+ }
105112
106- // to display
113+ // for display
114+ lv_draw_sw_rgb565_swap (cam_buf, 96 * 96 );
115+ for (int i = 0 ; i < kNumRows ; i++) {
116+ for (int j = 0 ; j < kNumCols ; j++) {
117+ uint16_t pixel = cam_buf[i * kNumCols + j];
107118 display_buf[2 * i * kNumCols * 2 + 2 * j] = pixel;
108119 display_buf[2 * i * kNumCols * 2 + 2 * j + 1 ] = pixel;
109120 display_buf[(2 * i + 1 ) * kNumCols * 2 + 2 * j] = pixel;
@@ -117,9 +128,9 @@ TfLiteStatus GetImage(int image_width, int image_height, int channels, int8_t* i
117128 for (int i = 0 ; i < image_width * image_height; i++) {
118129 image_data[i] = ((uint8_t *) fb->buf )[i] ^ 0x80 ;
119130 }
120- #endif // DISPLAY_SUPPORT
121131
122132 esp_camera_fb_return (fb);
133+ #endif // DISPLAY_SUPPORT
123134 /* here the esp camera can give you grayscale image directly */
124135 return kTfLiteOk ;
125136#else
0 commit comments