esp32-opencv
esp32-opencv copied to clipboard
[Fix] Enable JPEG support with `-DBUILD_JPEG_TURBO_DISABLE=ON` command
Reason
Opencv use libjpeg-turbo as the default option of jpeg library. However, according to the official page of libjpeg-turbe project,
libjpeg-turbo is a JPEG image codec that uses SIMD instructions (MMX, SSE2, AVX2, Neon, AltiVec) to accelerate baseline JPEG compression and decompression on x86, x86-64, Arm, and PowerPC systems
The native support for Xtensa platform is not available in libjpeg-turbo, which is why simply enabling -DBUILD_JPEG=ON during compilation may lead to failure
Solution
Use libjpeg instead of libjpeg-turbo. Add -DBUILD_JPEG_TURBO_DISABLE=ON to the cmake command.
Related Links
@SolomonLeon
We can build the esp_opencv_tests project with this procedure on esp-idf v5.3. https://github.com/joachimBurket/esp32-opencv/pull/23
$ idf.py --version
ESP-IDF v5.3-dirty
I converted the image file to jpeg using the convert command.
$ ls -l spiffs_images
合計 1200
-rw-rw-r-- 1 nop nop 709918 9月 6 14:54 1024x768.jpg
-rw-rw-r-- 1 nop nop 32953 9月 6 14:53 160x120.jpg
-rw-rw-r-- 1 nop nop 112751 9月 6 14:53 320x240.jpg
-rw-rw-r-- 1 nop nop 359939 9月 6 14:54 640x480.jpg
-rw-rw-r-- 1 nop nop 13 9月 6 13:01 hello.txt
I changed CMakeLists.txt:
# The following lines of boilerplate have to be in your project's
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
idf_build_set_property(COMPILE_OPTIONS "-DBUILD_JPEG_TURBO_DISABLE=ON" APPEND)
project(esp_opencv_tests)
I changed main/main.cpp.
void app_main(void)
{
// Needed for opencv linkage with pthread to work
pthread_cond_t cond_test = PTHREAD_COND_INITIALIZER;
pthread_cond_init(&cond_test, nullptr);
ESP_LOGI(TAG, "Starting main");
disp_mem_infos();
/* SPIFFS init */
init_spiffs();
ESP_LOGI(TAG, "done init_spiffs");
read_image_specific_res("/spiffs/160x120.jpg");
ESP_LOGI(TAG, "done read_image_specific_res /spiffs/160x120.jpg");
}
But i got this error.
W (2393) opencv_tests: cannot read the image: /spiffs/160x120.jpg
Do you have any advice?