pageauc / speed-camera

A Unix, Windows, Raspberry Pi Object Speed Camera using python, opencv, video streaming, motion tracking. Includes a Standalone Web Server Interface, Image Search using opencv template match and a whiptail Admin Menu Interface Includes picam and webcam Plugins for motion track security camera configuration including rclone sync script. watch-app allows remotely controller camera configuration from a remote storage service name. Uses sqlite3 and gnuplot for reporting. Recently added openalpr license plate reader support.
Apache License 2.0
960 stars 169 forks source link

Cannot run speed-cam.py - states "Could not import cv2 library" #148

Closed ninjadev64 closed 10 months ago

ninjadev64 commented 10 months ago

Hi there,

I'm trying to run speed-cam.py with Python 3.9.2 on a Raspberry Pi 4. I've installed OpenCV with sudo apt install python3-opencv and it has successfully installed itself. I've also installed it with Pip (pip install opencv-python) but that seems to have done nothing.

Additionally, the python- versions of all of the packages installed in the install script should be removed as they have all been replaced with python3- versions. This is the output of my run of the install script:

aman@octopi:~/speed-camera $ curl -L https://raw.github.com/pageauc/rpi-speed-camera/master/speed-install.sh | bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100  8618  100  8618    0     0  25272      0 --:--:-- --:--:-- --:--:-- 25272
-----------------------------------------------
Upgrade speed-camera speed-install.sh ver 13.17
-----------------------------------------------
Upgrade Download GitHub Files
Note: config.py will not be overwritten. Updated settings are in config.py.new
menubox.sh                                    100%[================================================================================================>]  25.81K  --.-KB/s    in 0.01s   
speed-cam.py                                  100%[================================================================================================>]  83.62K  --.-KB/s    in 0.04s   
sql_speed_gt.py                               100%[================================================================================================>]   5.72K  --.-KB/s    in 0.006s  
speed-cam.sh                                  100%[================================================================================================>]   1.22K  --.-KB/s    in 0s      
search-speed.py                               100%[================================================================================================>]  13.83K  --.-KB/s    in 0.02s   
search_config.py                              100%[================================================================================================>]   2.00K  --.-KB/s    in 0.004s  
Readme.md                                     100%[================================================================================================>]  14.83K  --.-KB/s    in 0.01s   
makehtml.py                                   100%[================================================================================================>]   8.87K  --.-KB/s    in 0.009s  
webserver.py                                  100%[================================================================================================>]  11.79K  --.-KB/s    in 0.008s  
webserver.sh                                  100%[================================================================================================>]   1.29K  --.-KB/s    in 0.001s  
alpr-speed.py                                 100%[================================================================================================>]   7.31K  --.-KB/s    in 0.004s  
sql-make-graph-count-totals.py                100%[================================================================================================>]  10.66K  --.-KB/s    in 0.01s   
sql-make-graph-speed-ave.py                   100%[================================================================================================>]  10.74K  --.-KB/s    in 0.007s  
strmcam.py                                    100%[================================================================================================>]   7.34K  --.-KB/s    in 0.004s  
strmusbipcam.py                               100%[================================================================================================>]   1.66K  --.-KB/s    in 0.001s  
strmpilegcam.py                               100%[================================================================================================>]   2.59K  --.-KB/s    in 0.004s  
strmpilibcam.py                               100%[================================================================================================>]   2.73K  --.-KB/s    in 0.001s  
media/webserver.txt                           100%[================================================================================================>]   1.06K  --.-KB/s    in 0.002s  
config.py.new                                 100%[================================================================================================>]  12.36K  --.-KB/s    in 0.01s   
INFO  : Upgrade Check/Install pi-timolo/plugins    Wait ...
INFO  : __init__.py plugin Found.  Skip Download ...
INFO  : picam240.py plugin Found.  Skip Download ...
INFO  : webcam240.py plugin Found.  Skip Download ...
INFO  : picam480.py plugin Found.  Skip Download ...
INFO  : webcam480.py plugin Found.  Skip Download ...
INFO  : rtsp352.py plugin Found.  Skip Download ...
INFO  : picam720.py plugin Found.  Skip Download ...
INFO  : webcam720.py plugin Found.  Skip Download ...
INFO  : picam1080.py plugin Found.  Skip Download ...
INFO  : secpicam480.py plugin Found.  Skip Download ...
INFO  : secwebcam480.py plugin Found.  Skip Download ...
INFO  : Upgrade Check/Install speed-camera/rclone-samples    Wait ...
rclone-security-copy.sh                       100%[================================================================================================>]   4.26K  --.-KB/s    in 0.005s  
rclone-security-sync.sh                       100%[================================================================================================>]   4.26K  --.-KB/s    in 0.007s  
rclone-security-sync-recent.sh                100%[================================================================================================>]   4.26K  --.-KB/s    in 0.004s  
rclone-cleanup.sh                             100%[================================================================================================>]   1.04K  --.-KB/s    in 0.001s  
rclone v1.64.2
- os/version: raspbian 11.8
- os/kernel: 6.1.21-v7l+ (armv7l)
- os/type: linux
- os/arch: arm (ARMv7 compatible)
- go/version: go1.21.3
- go/linking: static
- go/tags: none
Upgrade Make required Files Executable
Upgrade Installing speed-cam.py Dependencies
Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package python-opencv
Reading package lists...
Building dependency tree...
Reading state information...
python3-opencv is already the newest version (4.5.1+dfsg-5).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Reading package lists...
Building dependency tree...
Reading state information...
dos2unix is already the newest version (7.4.1-1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Reading package lists...
Building dependency tree...
Reading state information...
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 python-picamera : Depends: python (>= 2.7)
                   Depends: python (< 2.8)
                   Depends: python-numpy but it is not installable
E: Unable to correct problems, you have held broken packages.
Reading package lists...
Building dependency tree...
Reading state information...
python3-picamera is already the newest version (1.13).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package python-pil
Reading package lists...
Building dependency tree...
Reading state information...
python3-pil is already the newest version (8.1.2+dfsg-0.3+deb11u1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package python-imaging
Reading package lists...
Building dependency tree...
Reading state information...
Package python3-imaging is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
However the following packages replace it:
  python3-pil

E: Package 'python3-imaging' has no installation candidate
Reading package lists...
Building dependency tree...
Reading state information...
sqlite3 is already the newest version (3.34.1-3).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Reading package lists...
Building dependency tree...
Reading state information...
Package python-matplotlib is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'python-matplotlib' has no installation candidate
Reading package lists...
Building dependency tree...
Reading state information...
python3-matplotlib is already the newest version (3.3.4-1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Reading package lists...
Building dependency tree...
Reading state information...
python3-numpy is already the newest version (1:1.19.5-1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Reading package lists...
Building dependency tree...
Reading state information...
libgl1-mesa-dri is already the newest version (20.3.5-1+rpt5+rpi1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Reading package lists...
Building dependency tree...
Reading state information...
fonts-freefont-ttf is already the newest version (20120503-10).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Reading package lists...
Building dependency tree...
Reading state information...
pandoc is already the newest version (2.9.2.1-1+deb11u1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

-----------------------------------------------
Upgrade Complete
-----------------------------------------------
1. Reboot RPI if there are significant Raspbian system updates
2. Raspberry pi optionally needs a monitor/TV attached to display openCV window
3. Run speed-cam.py in SSH Terminal (default) or optional GUI Desktop
   Review and modify the config.py settings as required using nano editor
4. To start speed-cam open SSH or a GUI desktop Terminal session
   and change to speed-camera folder and launch per commands below

   cd ~/speed-camera
   ./speed-cam.py

Calibrate speed camera per wiki instructions.  After Calibration is complete
set config.py variable calibrate = False

Run from Admin menu per

   ./menubox.sh

IMPORTANT: speed-cam.py ver 8.x Requires Updated config.py and plugins

    cd ~/speed-camera
    cp config.py config.py.bak
    cp config.py.new config.py

To replace plugins rename plugins folder per below

    cd ~/speed-camera
    mv plugins pluginsold

Then run menubox.sh UPGRADE menu pick.

-----------------------------------------------
For Detailed Instructions See https://github.com/pageauc/speed-camera/wiki
speed-camera version 13.17
Good Luck Claude ...
Bye

This is the error message that I get:

aman@octopi:~/speed-camera $ python3 speed-cam.py
Loading Wait...
----------------------------------------------------------------------
speed-cam.py 13.17  written by Claude Pageau
Motion Track Largest Moving Object and Calculate Speed per Calibration.
----------------------------------------------------------------------
2023-10-24 19:19:19 ERROR    <module>   Could Not import cv2 library
2023-10-24 19:19:19 ERROR    <module>   python3 failed to import cv2
2023-10-24 19:19:19 ERROR    <module>   Try installing opencv for python3
2023-10-24 19:19:19 ERROR    <module>   For RPI See https://github.com/pageauc/opencv3-setup
2023-10-24 19:19:19 ERROR    <module>   speed-cam.py 13.17 Exiting Due to Error

I tried the GitHub script mentioned in that error message but I get this error when running make compile and make install:

[ 22%] Building CXX object 3rdparty/carotene/hal/carotene/CMakeFiles/carotene_objs.dir/src/absdiff.cpp.o
c++: error: unrecognized command-line option ‘--param=ipcp-unit-growth=100000’; did you mean ‘--param=ipa-cp-unit-growth=’?
make[2]: *** [3rdparty/carotene/hal/carotene/CMakeFiles/carotene_objs.dir/build.make:82: 3rdparty/carotene/hal/carotene/CMakeFiles/carotene_objs.dir/src/absdiff.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:3609: 3rdparty/carotene/hal/carotene/CMakeFiles/carotene_objs.dir/all] Error 2
ninjadev64 commented 10 months ago

(@pageauc)

pageauc commented 10 months ago

I have Run the install on several different RPI's including Libre and various RPI OS versions under python2 (older distros) and python3 under bullseye 32 and 64 (RPI4) without issue. Other users have not reported any install or opencv issues. From the install script it is obvious that cv2 is installed. Can you import cv2 from a python command shell.

python3
>>import cv2
>>print(cv2.__version__)
>>exit()

You should get the python version number. If not there may be a corrupt python lib .so file or path problem. This can happen with a download/install glitch. It may also be a corrupt SD. You should try a fresh SD card and burn a new RPI OS image (Bullseye) I have not tested with bookworm yet but would not expect any problems. Thanks for your detailed information Claude ...

Claude ....

On Tue, Oct 24, 2023 at 3:36 PM ninjadev64 @.***> wrote:

@.*** https://github.com/pageauc)

— Reply to this email directly, view it on GitHub https://github.com/pageauc/speed-camera/issues/148#issuecomment-1777906036, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABNPKZDEFBBWPLC3H52RT2DYBAKFBAVCNFSM6AAAAAA6OGW7PGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONZXHEYDMMBTGY . You are receiving this because you were mentioned.Message ID: @.***>

-- YouTube Channel at https://www.youtube.com/user/pageaucp http://www.youtube.com/user/pageaucp GitHub Repository at https://github.com/pageauc

pageauc commented 10 months ago

BTW It is a good practice to perform a sudo apt update followed by a sudo apt upgrade before doing any software install Claude ....

On Tue, Oct 24, 2023 at 6:11 PM Claude Pageau @.***> wrote:

I have Run the install on several different RPI's including Libre and various RPI OS versions under python2 (older distros) and python3 under bullseye 32 and 64 (RPI4) without issue. Other users have not reported any install or opencv issues. From the install script it is obvious that cv2 is installed. Can you import cv2 from a python command shell.

python3
>>import cv2
>>print(cv2.__version__)
>>exit()

You should get the python version number. If not there may be a corrupt python lib .so file or path problem. This can happen with a download glitch. It may also be a corrupt SD. You should try a fresh SD card and burn a new RPI OS image (Bullseye) I have not tested with bookworm yet but would not expect any problems. Thanks for your detailed information Claude ...

Claude ....

On Tue, Oct 24, 2023 at 3:36 PM ninjadev64 @.***> wrote:

@.*** https://github.com/pageauc)

— Reply to this email directly, view it on GitHub https://github.com/pageauc/speed-camera/issues/148#issuecomment-1777906036, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABNPKZDEFBBWPLC3H52RT2DYBAKFBAVCNFSM6AAAAAA6OGW7PGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONZXHEYDMMBTGY . You are receiving this because you were mentioned.Message ID: @.***>

-- YouTube Channel at https://www.youtube.com/user/pageaucp http://www.youtube.com/user/pageaucp GitHub Repository at https://github.com/pageauc

-- YouTube Channel at https://www.youtube.com/user/pageaucp http://www.youtube.com/user/pageaucp GitHub Repository at https://github.com/pageauc

pageauc commented 10 months ago

FYI Just created a bookworm 32 SD using pi Imager with predone settings for WIFI, SSH, HOSTNAME, Etc. Note I default initial hostname to rpi-noname so it is easier to login with SSH. inserted SD in RPI4. Booted and after RPI initial setup that takes a bit of time, I SSH Iogged in and did update and upgrade then did the curl speed-camera install. Had a RPI camera already installed. Changed config.py to turn off calibration since this was just for testing. speed-cam.py ran fine with default libcam setting. No problems.

If I get time I will do bookworm 64 test I suspect your SD has a problem. Claude ....

On Tue, Oct 24, 2023 at 6:39 PM Claude Pageau @.***> wrote:

BTW It is a good practice to perform a sudo apt update followed by a sudo apt upgrade before doing any software install Claude ....

On Tue, Oct 24, 2023 at 6:11 PM Claude Pageau @.***> wrote:

I have Run the install on several different RPI's including Libre and various RPI OS versions under python2 (older distros) and python3 under bullseye 32 and 64 (RPI4) without issue. Other users have not reported any install or opencv issues. From the install script it is obvious that cv2 is installed. Can you import cv2 from a python command shell.

python3
>>import cv2
>>print(cv2.__version__)
>>exit()

You should get the python version number. If not there may be a corrupt python lib .so file or path problem. This can happen with a download glitch. It may also be a corrupt SD. You should try a fresh SD card and burn a new RPI OS image (Bullseye) I have not tested with bookworm yet but would not expect any problems. Thanks for your detailed information Claude ...

Claude ....

On Tue, Oct 24, 2023 at 3:36 PM ninjadev64 @.***> wrote:

@.*** https://github.com/pageauc)

— Reply to this email directly, view it on GitHub https://github.com/pageauc/speed-camera/issues/148#issuecomment-1777906036, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABNPKZDEFBBWPLC3H52RT2DYBAKFBAVCNFSM6AAAAAA6OGW7PGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONZXHEYDMMBTGY . You are receiving this because you were mentioned.Message ID: @.***>

-- YouTube Channel at https://www.youtube.com/user/pageaucp http://www.youtube.com/user/pageaucp GitHub Repository at https://github.com/pageauc

-- YouTube Channel at https://www.youtube.com/user/pageaucp http://www.youtube.com/user/pageaucp GitHub Repository at https://github.com/pageauc

-- YouTube Channel at https://www.youtube.com/user/pageaucp http://www.youtube.com/user/pageaucp GitHub Repository at https://github.com/pageauc

pageauc commented 10 months ago

Just completed 64 bit bookworm install. Did same steps as above. Note. Did NOT run raspi-config. picamera defaults to libcamera and is enabled by default. speed-cam.py ran with no issues. Let me know how you make out with resolving your problem.

Regards Claude.

On Tue, Oct 24, 2023 at 7:55 PM Claude Pageau @.***> wrote:

FYI Just created a bookworm 32 SD using pi Imager with predone settings for WIFI, SSH, HOSTNAME, Etc. Note I default initial hostname to rpi-noname so it is easier to login with SSH. inserted SD in RPI4. Booted and after RPI initial setup that takes a bit of time, I SSH Iogged in and did update and upgrade then did the curl speed-camera install. Had a RPI camera already installed. Changed config.py to turn off calibration since this was just for testing. speed-cam.py ran fine with default libcam setting. No problems.

If I get time I will do bookworm 64 test I suspect your SD has a problem. Claude ....

On Tue, Oct 24, 2023 at 6:39 PM Claude Pageau @.***> wrote:

BTW It is a good practice to perform a sudo apt update followed by a sudo apt upgrade before doing any software install Claude ....

On Tue, Oct 24, 2023 at 6:11 PM Claude Pageau @.***> wrote:

I have Run the install on several different RPI's including Libre and various RPI OS versions under python2 (older distros) and python3 under bullseye 32 and 64 (RPI4) without issue. Other users have not reported any install or opencv issues. From the install script it is obvious that cv2 is installed. Can you import cv2 from a python command shell.

python3
>>import cv2
>>print(cv2.__version__)
>>exit()

You should get the python version number. If not there may be a corrupt python lib .so file or path problem. This can happen with a download glitch. It may also be a corrupt SD. You should try a fresh SD card and burn a new RPI OS image (Bullseye) I have not tested with bookworm yet but would not expect any problems. Thanks for your detailed information Claude ...

Claude ....

On Tue, Oct 24, 2023 at 3:36 PM ninjadev64 @.***> wrote:

@.*** https://github.com/pageauc)

— Reply to this email directly, view it on GitHub https://github.com/pageauc/speed-camera/issues/148#issuecomment-1777906036, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABNPKZDEFBBWPLC3H52RT2DYBAKFBAVCNFSM6AAAAAA6OGW7PGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONZXHEYDMMBTGY . You are receiving this because you were mentioned.Message ID: @.***>

-- YouTube Channel at https://www.youtube.com/user/pageaucp http://www.youtube.com/user/pageaucp GitHub Repository at https://github.com/pageauc

-- YouTube Channel at https://www.youtube.com/user/pageaucp http://www.youtube.com/user/pageaucp GitHub Repository at https://github.com/pageauc

-- YouTube Channel at https://www.youtube.com/user/pageaucp http://www.youtube.com/user/pageaucp GitHub Repository at https://github.com/pageauc

-- YouTube Channel at https://www.youtube.com/user/pageaucp http://www.youtube.com/user/pageaucp GitHub Repository at https://github.com/pageauc

ninjadev64 commented 10 months ago

BTW It is a good practice to perform a sudo apt update followed by a sudo

apt upgrade before doing any software install

Claude ....

Yes, I did do this (it took nearly 1 hour 😅)

ninjadev64 commented 10 months ago

You should get the python version number. If not there may be a corrupt python lib .so file or path problem. This can happen with a download glitch.

Yep, it was this.

aman@octopi:~ $ python3
Python 3.9.2 (default, Mar 12 2021, 04:06:34) 
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/aman/.local/lib/python3.9/site-packages/cv2/__init__.py", line 181, in <module>
    bootstrap()
  File "/home/aman/.local/lib/python3.9/site-packages/cv2/__init__.py", line 153, in bootstrap
    native_module = importlib.import_module("cv2")
  File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ImportError: /home/aman/.local/lib/python3.9/site-packages/cv2/cv2.abi3.so: undefined symbol: __atomic_store_8
>>> 

How should I restore this file?

ninjadev64 commented 10 months ago

I solved it!

I had it installed both with pip and with apt. There was something wrong with the pip version but it was still preferring it.

pip uninstall opencv-python did the trick.