Hi,
running this benchmark on a raspi 4 I expected simplejpeg to win the comparison by far - but it does actually lag behind, as far as I can see my OpenCV version doesn’t use libjpeg-turbo, so what could be the reason for this?
opencv config:
Summary
General configuration for OpenCV 4.6.0 =====================================
Version control: unknown
Platform:
Timestamp: 2022-06-08T21:56:33Z
Host: Linux 5.15.32-v7l+ armv7l
CMake: 3.22.4
CMake generator: Unix Makefiles
CMake build tool: /usr/bin/gmake
Configuration: Release
CPU/HW features:
Baseline:
requested: DETECT
C/C++:
Built as dynamic libs?: NO
C++ standard: 11
C++ Compiler: /usr/bin/c++ (ver 10.2.1)
C++ flags (Release): -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG -DNDEBUG
C++ flags (Debug): -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -fvisibility=hidden -fvisibility-inlines-hidden -g -O0 -DDEBUG -D_DEBUG
C Compiler: /usr/bin/cc
C flags (Release): -fsigned-char -W -Wall -Wreturn-type -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -fvisibility=hidden -O3 -DNDEBUG -DNDEBUG
C flags (Debug): -fsigned-char -W -Wall -Wreturn-type -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -fvisibility=hidden -g -O0 -DDEBUG -D_DEBUG
Linker flags (Release): -Wl,–gc-sections -Wl,–as-needed -Wl,–no-undefined
Linker flags (Debug): -Wl,–gc-sections -Wl,–as-needed -Wl,–no-undefined
ccache: NO
Precompiled headers: NO
Extra dependencies: /usr/lib/arm-linux-gnueabihf/liblapack.so /usr/lib/arm-linux-gnueabihf/libcblas.so /usr/lib/arm-linux-gnueabihf/libatlas.so /usr/lib/arm-linux-gnueabihf/libjpeg.so /usr/lib/arm-linux-gnueabihf/libwebp.so /usr/lib/arm-linux-gnueabihf/libpng.so /usr/lib/arm-linux-gnueabihf/libtiff.so openjp2 /usr/lib/arm-linux-gnueabihf/libz.so dl m pthread rt
3rdparty dependencies: libprotobuf ade ittnotify IlmImf quirc
OpenCV modules:
To be built: calib3d core dnn features2d flann gapi highgui imgcodecs imgproc ml objdetect photo python3 stitching video videoio
Disabled: world
Disabled by dependency: -
Unavailable: java python2 ts
Applications: -
Documentation: NO
Non-free algorithms: NO
GUI: GTK3
GTK+: YES (ver 3.24.24)
GThread : YES (ver 2.66.8)
GtkGlExt: NO
VTK support: NO
Media I/O:
ZLib: /usr/lib/arm-linux-gnueabihf/libz.so (ver 1.2.11)
JPEG: /usr/lib/arm-linux-gnueabihf/libjpeg.so (ver 62)
WEBP: /usr/lib/arm-linux-gnueabihf/libwebp.so (ver encoder: 0x020e)
PNG: /usr/lib/arm-linux-gnueabihf/libpng.so (ver 1.6.37)
TIFF: /usr/lib/arm-linux-gnueabihf/libtiff.so (ver 42 / 4.2.0)
JPEG 2000: OpenJPEG (ver 2.4.0)
OpenEXR: build (ver 2.3.0)
HDR: YES
SUNRASTER: YES
PXM: YES
PFM: YES
Video I/O:
DC1394: NO
FFMPEG: YES
avcodec: YES (58.91.100)
avformat: YES (58.45.100)
avutil: YES (56.51.100)
swscale: YES (5.7.100)
avresample: NO
GStreamer: NO
v4l/v4l2: YES (linux/videodev2.h)
Parallel framework: pthreads
Trace: YES (with Intel ITT)
Other third-party libraries:
Lapack: YES (/usr/lib/arm-linux-gnueabihf/liblapack.so /usr/lib/arm-linux-gnueabihf/libcblas.so /usr/lib/arm-linux-gnueabihf/libatlas.so)
Eigen: YES (ver 3.3.9)
Custom HAL: NO
Protobuf: build (3.19.1)
OpenCL: YES (no extra features)
Include path: /tmp/pip-wheel-u79916uk/opencv-python_ea2489746b3a43bfb3f2b5331b7ab47a/opencv/3rdparty/include/opencl/1.2
Link libraries: Dynamic load
Python 3:
Interpreter: /usr/bin/python3 (ver 3.9.2)
Libraries: /usr/lib/arm-linux-gnueabihf/libpython3.9.so (ver 3.9.2)
numpy: /usr/local/lib/python3.9/dist-packages/numpy/core/include (ver 1.22.3)
install path: python/cv2/python-3
Python (for build): /usr/bin/python3
Java:
ant: NO
JNI: NO
Java wrappers: NO
Java tests: NO
Install to: /tmp/pip-wheel-u79916uk/opencv-python_ea2489746b3a43bfb3f2b5331b7ab47a/_skbuild/linux-armv7l-3.9/cmake-install
import cv2
import numpy as np
from simplejpeg import encode_jpeg
import time
import threading
# Create 10 random 2K images
num_images = 10
image_list = [np.random.randint(0, 256, (1080, 2048, 3), dtype=np.uint8) for _ in range(num_images)]
def benchmark_opencv(images, results):
durations = []
for idx, img in enumerate(images):
start_time = time.time()
cv2.imwrite(f'temp_opencv_{idx}.jpg', img)
durations.append(time.time() - start_time)
print(f"OpenCV: Image {idx + 1} saved.")
results['opencv'] = durations
def benchmark_simplejpeg(images, results):
durations = []
for idx, img in enumerate(images):
start_time = time.time()
jpeg_data = encode_jpeg(img)
with open(f'temp_simplejpeg_{idx}.jpg', 'wb') as f:
f.write(jpeg_data)
durations.append(time.time() - start_time)
print(f"simplejpeg: Image {idx + 1} encoded and saved.")
results['simplejpeg'] = durations
results = {}
# Create threads
opencv_thread = threading.Thread(target=benchmark_opencv, args=(image_list, results))
simplejpeg_thread = threading.Thread(target=benchmark_simplejpeg, args=(image_list, results))
# Start threads
opencv_thread.start()
simplejpeg_thread.start()
# Wait for both threads to finish
opencv_thread.join()
simplejpeg_thread.join()
# Analyze the timings
print(f"\nOpenCV Average: {np.mean(results['opencv']):.5f} seconds")
print(f"simplejpeg Average: {np.mean(results['simplejpeg']):.5f} seconds")
print(f"OpenCV Total: {sum(results['opencv']):.5f} seconds")
print(f"simplejpeg Total: {sum(results['simplejpeg']):.5f} seconds")
OpenCV Average: 0.17318 seconds
simplejpeg Average: 0.25848 seconds
OpenCV Total: 1.73184 seconds
simplejpeg Total: 2.58479 seconds