[PYTHON] Why detectMultiScale () is slow on Raspberry Pi B +

When the person detector is operated with the combination of OpenCV + Python, The processing speed is much slower than expected from the clock speed I felt it with Raspberry Pi B +. Make a note of the reason.

hog=cv2.HOGDescriptor() hog.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector()) hogParams = {'winStride': (8, 8), 'padding': (32, 32), 'scale': 1.05} human, r = hog.detectMultiScale(im, **hogParams)

A method called detectMultiScale () is used by multiple threads on Intel's multi-core CPUs. That's why ARM's single-core Raspberry Pi B + doesn't work with multiple threads.

If you look at the description of hog.cpp in the actual module, you can see that the detection processing is performed in parallel for each image size as shown below. void HOGDescriptor::detectMultiScale( const Mat& img, vector& foundLocations, vector& foundWeights, double hitThreshold, Size winStride, Size padding, double scale0, double finalThreshold, bool useMeanshiftGrouping) const { //中略 parallel_for_(Range(0, (int)levelScale.size()), HOGInvoker(this, img, hitThreshold, winStride, padding, &levelScale[0], &allCandidates, &mtx, &tempWeights, &tempScales)); //後略 }

In fact, in Windows Task Manager, Performance Looking at the operating status of each core in At the time of detectMultiScale (), you can see that multiple cores are working. On the other hand, detect () does not do that.

This is the same for C ++ and Python.

Since it is implemented using Intel Threading Building Blocks (TBB) RaspberryPi2 quad core, unless you have another multithreaded implementation It seems that the benefits of quad core will not be enjoyed.

Postscript: cv::parallel_for_ Please refer to the added reference material on how to use. cv::parallel_for_ Seems to manage threads in another framework in environments where Intel TBB is not available. In TBB, it is said that the creation and termination of threads are not explicitly described.

Postscript: Parallel processing by OpenCV TBB It describes how to install TBB and changes during CMake of OpenCV.

Threading Building Blocks It is essential to CMake after getting.

OpenCV memorandum I built OpenCV 2.4.11 with Raspberry Pi 2 [Building OpenCV 2.4.10 on Raspberry Pi 2] (http://iwaki2009.blogspot.jp/2015/02/raspberry-pi-2-opencv-2410.html) According to the Raspberry Pi 2, you can install TBB from source. The latter article describes the settings for CMake.

** References ** "Parallelization and speeding up of processing by TBB" http://opencv.jp/opencv2-x-tips/opencv_performance_with_tbb

"Try using cv :: parallel_for_" https://github.com/atinfinity/lab/wiki/cv :: parallel_for_% E3% 82% 92% E4% BD% BF% E3% 81% A3% E3% 81% A6% E3% 81% BF% E3% 82% 8B

Recommended Posts

Why detectMultiScale () is slow on Raspberry Pi B +
USB boot on Raspberry Pi 4 Model B
Build OpenCV-Python environment on Raspberry Pi B +
pigpio on Raspberry pi
Introduced Ceph on Kubernetes on Raspberry Pi 4B (ARM64)
Cython on Raspberry Pi
Raspberry Pi 4B initial setting
raspberry pi 1 model b, python
Introduced pyenv on Raspberry Pi
Use NeoPixel on Raspberry Pi
Install OpenCV4 on Raspberry Pi 3
Install TensorFlow 1.15.0 on Raspberry Pi
[Note] Installing vmware ESXi on Arm Fling on Raspberry Pi 4B
Port FreeRTOS to Raspberry Pi 4B
Testing uart communication on Raspberry Pi
raspberry pi 1 model b, node-red part 17
MQTT on Raspberry Pi and Mac
raspberry pi 4 centos7 install on docker
Install ghoto2 on Raspberry Pi (memo)
Try using ArUco on Raspberry Pi
OpenCV installation procedure on Raspberry Pi
Power on / off Raspberry pi on Arduino
Detect switch status on Raspberry Pi 3
Install OpenMedia Vault 5 on Raspberry Pi 4
L Chika on Raspberry Pi C #
Build wxPython on Ubuntu 20.04 on raspberry pi 4
Phone notification when surveillance camera motion is detected on Raspberry Pi
"Honwaka Notification Lamp" on Raspberry Pi Part 2
Detect "brightness" using python on Raspberry Pi 3!
"Honwaka Notification Lamp" on Raspberry Pi Part 1
Enable UART + serial communication on Raspberry Pi
Adafruit Python BluefruitLE works on Raspberry Pi.
Accelerate Deep Learning on Raspberry Pi 4 CPU
Set swap space on Ubuntu on Raspberry Pi
Programming normally with Node-RED programming on Raspberry Pi 3
Use the Grove sensor on the Raspberry Pi
Install 64-bit OS (bate) on Raspberry Pi
IPv6 should be disabled when ssh of Raspberry Pi 4 is very slow
Install docker-compose on 64-bit Raspberry Pi OS
Run servomotor on Raspberry Pi 3 using python
"Honwaka Notification Lamp" on Raspberry Pi Part 3
Working with sensors on Mathematica on Raspberry Pi
Detect temperature using python on Raspberry Pi 3!
Mount Windows shared folder on Raspberry Pi
Matrix multiplication on Raspberry Pi GPU (Part 2)
How to install NumPy on Raspberry Pi
I installed OpenCV-Python on my Raspberry Pi
Working with GPS on Raspberry Pi 3 Python
I tried running Flask on Raspberry Pi 3 Model B + using Nginx and uWSGI
Detect slide switches using python on Raspberry Pi 3!
Build a Django environment on Raspberry Pi (MySQL)
Try using a QR code on a Raspberry Pi
Detect magnet switches using python on Raspberry Pi 3!
Enjoy electronic work with GPIO on Raspberry Pi
Power on / off your PC with raspberry pi
Use Grove-Temperature & Humidity Sensor (DHT11) on Raspberry Pi
Make DHT11 available on Raspberry Pi + python (memo)
Beginning cross-compilation for Raspberry Pi Zero on Ubuntu
Sound the buzzer using python on Raspberry Pi 3!
Play with your Ubuntu desktop on your Raspberry Pi 4
Display CPU temperature every 5 seconds on Raspberry Pi 4