OM222O
Posts: 22
Joined: Mon Feb 03, 2020 11:03 pm

Machine Vision using raspberry pi (3B+)

Fri May 14, 2021 4:18 am

Hello everyone,
I have created a machine vision library in Python which has some promising results on a intel based machine (CPU rendering only). I wanted to test my code on a raspberry pi to see if it's viable for robotics application or if I had to build a custom FPGA accelerator (the processing has to be done in real time, preferably at least 30FPS). Unfortunately I have tried everything but I can't get opencv to install my pi (literally followed dozens of tutorials, reinstalled different versions of raspbian, even tried miniconda to install packages).

The code can be found on github: https://github.com/2332575y/retina
If anyone can test the code on their pi, please let me know so I can send you the benchmark scripts (requires a webcam (the raspberry camera is not an option, has to be via USB)).

Honestly this has taken me so long to try and install opencv, that I have came up with a completely new implementation of the code that should reduce the memory bandwidth problems I had , but I can't test either version to find the bottlenecks on an SOC like the pi. I just want to have a quick check as to whether this is even feasible on a pi or if I should stop wasting time and move on to FPGAs.

Edit:
The required libraries for the codes to work are:
Cython
Numpy
OpenCV
skimage.io
matplotlib

gordon77
Posts: 5673
Joined: Sun Aug 05, 2012 3:12 pm

Re: Machine Vision using raspberry pi (3B+)

Fri May 14, 2021 4:59 am

Tried sudo apt-get install python3-opencv ?

OM222O
Posts: 22
Joined: Mon Feb 03, 2020 11:03 pm

Re: Machine Vision using raspberry pi (3B+)

Fri May 14, 2021 2:11 pm

gordon77 wrote:Tried sudo apt-get install python3-opencv ?
I have "successfully" installed it at least with a few different methods:

Image

but as you can see, every time I actually try to use it, I get an import error.
I have tried pip install, tried downloading the project and running the makefile and pretty much tried all the tutorials you can find on google. I have no idea why it doesn't wanna work for me :( :( :(

User avatar
DougieLawson
Posts: 41297
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Machine Vision using raspberry pi (3B+)

Fri May 14, 2021 4:49 pm

Try running everything with python3 rather than python (which gets you python2).
Any language using left-hand whitespace for syntax is ridiculous

Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.

Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

OM222O
Posts: 22
Joined: Mon Feb 03, 2020 11:03 pm

Re: Machine Vision using raspberry pi (3B+)

Fri May 14, 2021 5:31 pm

DougieLawson wrote:
Fri May 14, 2021 4:49 pm
Try running everything with python3 rather than python (which gets you python2).
I have changed the default interpreter to python3, and even then, as you can see from the picture above, I used pip3 install and tried both python3 and python2, neither of which could find cv2 :( frankly this is a bit ridiculous how hard it is to install opencv on the pi. On windows it's extremely easy, on linux it's a bit more difficult but still works on my VM, however the pi is just refusing to cooperate ...
Is there an image of raspbian with opencv pre installed? If so I think that'd be my only option at this point.

I wouldn't be asking others to test my code if I wasn't desperate :|

gordon77
Posts: 5673
Joined: Sun Aug 05, 2012 3:12 pm

Re: Machine Vision using raspberry pi (3B+)

Fri May 14, 2021 7:11 pm

From https://www.piwheels.org/project/opencv-contrib-python/ does it mean the version you have installed isn't compatible with stretch / buster ?

Why is your python 3.4.3 ?
Attachments
IMG_20210514_200841.jpg
IMG_20210514_200841.jpg (38.1 KiB) Viewed 500 times

OM222O
Posts: 22
Joined: Mon Feb 03, 2020 11:03 pm

Re: Machine Vision using raspberry pi (3B+)

Fri May 14, 2021 10:09 pm

To be completely honest I have no idea what stretch or buster are; Does it mean I should try to install the 4.4.0.46 version? It's the only "Build successful" I can see from the list.

Why is my python 3.4.3? It's what was there on the pi ... I don't really think it matters that much and upgrading it to 3.10 is probably a good idea, but after having so many issues with such a basic thing like installing a python library, I'm not sure I'm ready to take on upgrading the whole python interpreter ...

User avatar
DougieLawson
Posts: 41297
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Machine Vision using raspberry pi (3B+)

Fri May 14, 2021 10:55 pm

Time to get a new 16GB (minimum, 32GB is better) SDCard and install a fresh copy of RaspiOS.

That will get you singing from the same song sheet as the folks who are trying to help you.
Any language using left-hand whitespace for syntax is ridiculous

Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.

Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

OM222O
Posts: 22
Joined: Mon Feb 03, 2020 11:03 pm

Re: Machine Vision using raspberry pi (3B+)

Sat May 15, 2021 12:07 am

The current one I'm using was downloaded last week from this link: https://www.raspberrypi.org/software/operating-systems/

The exact version:

Raspberry Pi OS with desktop

Release date: March 4th 2021
Kernel version: 5.10
Size: 1,175MB

Is there a newer version? unless I'm missing, that image comes with python 3.4
Honestly I don't mind reinstalling it again if anyone can link to a tutorial that installs opencv correctly using that image :(

Edit: Using a 16GB SD card and I made sure to expand the storage on the pi from: sudo raspi-config

gordon77
Posts: 5673
Joined: Sun Aug 05, 2012 3:12 pm

Re: Machine Vision using raspberry pi (3B+)

Sat May 15, 2021 6:10 am

I'm confused because the latest version l installed of raspios came with python3.7.3.

Then l just use sudo apt install python3-opencv

Admittedly not the latest opencv but works for me.

OM222O
Posts: 22
Joined: Mon Feb 03, 2020 11:03 pm

Re: Machine Vision using raspberry pi (3B+)

Sat May 15, 2021 3:10 pm

I am even more confused:
Image

but that seems to be a common theme when working with linux :lol:
It says that python 3.7 is selected but running python --version says it's actually 3.4 so I have no idea what's going on there :?

Can you please point me to a guide for a clean install which uses python 3.7? I have pieced this installation together from different information I could find by googling each step but I couldn't find a good walk through that explains each step.

gordon77
Posts: 5673
Joined: Sun Aug 05, 2012 3:12 pm

Re: Machine Vision using raspberry pi (3B+)

Sat May 15, 2021 4:12 pm

I don't have the answers, maybe when you changed the default interpreter to python3 things got confused.

I'd reinstall raspios and try my suggestion for opencv install and see if that works.

il_diavolo
Posts: 161
Joined: Mon Dec 02, 2013 7:56 pm

Re: Machine Vision using raspberry pi (3B+)

Sat May 15, 2021 9:04 pm

Sorry, slightly off topic, but if one installs cv2 as suggested by Gordon77 "sudo apt install python3-opencv" does that include the "not free" SIFT and SURF methods? For a use example, "detector = cv2.xfeatures2d.SURF_create(100)"

gordon77
Posts: 5673
Joined: Sun Aug 05, 2012 3:12 pm

Re: Machine Vision using raspberry pi (3B+)

Sun May 16, 2021 7:41 am

The answer appears to be no.

This may explain https://stackoverflow.com/questions/645 ... 3-opencv-4

Return to “General discussion”