1-
21/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
32
43Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,16 +12,14 @@ 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+ #include " esp_heap_caps.h"
2221#include " esp_log.h"
23- #include " esp_spi_flash.h"
24- #include " esp_system.h"
25- #include " esp_timer.h"
22+ #include " bsp/esp-bsp.h"
2623
2724#include " app_camera_esp.h"
2825#include " esp_camera.h"
@@ -31,8 +28,7 @@ limitations under the License.
3128#include " esp_main.h"
3229
3330static const char * TAG = " app_camera" ;
34-
35- static uint16_t *display_buf; // buffer to hold data to be sent to display
31+ static uint16_t * display_buf;
3632
3733// Get the camera module ready
3834TfLiteStatus InitCamera () {
@@ -84,13 +80,19 @@ TfLiteStatus GetImage(int image_width, int image_height, int channels, int8_t* i
8480 // In case if display support is enabled, we initialise camera in rgb mode
8581 // Hence, we need to convert this data to grayscale to send it to tf model
8682 // For display we extra-polate the data to 192X192
83+
84+ // point to the last quarter of buffer
85+ uint16_t * cam_buf = display_buf + (96 * 96 * 3 );
86+ memcpy ((uint8_t *)cam_buf, fb->buf , fb->len );
87+ esp_camera_fb_return (fb);
88+
8789 for (int i = 0 ; i < kNumRows ; i++) {
8890 for (int j = 0 ; j < kNumCols ; j++) {
89- uint16_t pixel = (( uint16_t *) (fb-> buf )) [i * kNumCols + j];
91+ uint16_t inference_pixel = cam_buf [i * kNumCols + j];
9092
9193 // for inference
92- uint8_t hb = pixel & 0xFF ;
93- uint8_t lb = pixel >> 8 ;
94+ uint8_t hb = inference_pixel & 0xFF ;
95+ uint8_t lb = inference_pixel >> 8 ;
9496 uint8_t r = (lb & 0x1F ) << 3 ;
9597 uint8_t g = ((hb & 0x07 ) << 5 ) | ((lb & 0xE0 ) >> 3 );
9698 uint8_t b = (hb & 0xF8 );
@@ -102,8 +104,14 @@ TfLiteStatus GetImage(int image_width, int image_height, int channels, int8_t* i
102104 int8_t grey_pixel = ((305 * r + 600 * g + 119 * b) >> 10 ) - 128 ;
103105
104106 image_data[i * kNumCols + j] = grey_pixel;
107+ }
108+ }
105109
106- // to display
110+ // for display
111+ lv_draw_sw_rgb565_swap (cam_buf, 96 * 96 );
112+ for (int i = 0 ; i < kNumRows ; i++) {
113+ for (int j = 0 ; j < kNumCols ; j++) {
114+ uint16_t pixel = cam_buf[i * kNumCols + j];
107115 display_buf[2 * i * kNumCols * 2 + 2 * j] = pixel;
108116 display_buf[2 * i * kNumCols * 2 + 2 * j + 1 ] = pixel;
109117 display_buf[(2 * i + 1 ) * kNumCols * 2 + 2 * j] = pixel;
@@ -118,8 +126,6 @@ TfLiteStatus GetImage(int image_width, int image_height, int channels, int8_t* i
118126 image_data[i] = ((uint8_t *) fb->buf )[i] ^ 0x80 ;
119127 }
120128#endif // DISPLAY_SUPPORT
121-
122- esp_camera_fb_return (fb);
123129 /* here the esp camera can give you grayscale image directly */
124130 return kTfLiteOk ;
125131#else
0 commit comments