can't run tutorial example... what did I miss?

OpenCV, Python and other image processing questions
Post Reply
gtoal
Posts: 9
Joined: Thu Apr 25, 2019 8:58 pm

can't run tutorial example... what did I miss?

Post by gtoal »

New stereopi user here - just started today so this is likely a newbie problem...

Hooked up StereoPi with 4Gb CM module. Using the pre-installed Rasbian that came with CM module, not the SLP image.
(still downloading, I have a pretty slow internet connection)

Updated, upgraded, and rpi-upgraded.
Installed omxplayer and fbi.
Installed dt-blob.bin, tested both cameras work, can record and view stereo images - both stills and video.

sudo apt-get install python-picamera python3-picamera
sudo apt install python-opencv
wget https://github.com/realizator/stereopi- ... master.zip
unzip master.zip; mv stereopi-tutorial-master stereopi-tutorial

Can't run the tutorial example under python3:

pi@stereopi:~/stereopi-tutorial $ python3 1_test.py
Traceback (most recent call last):
File "1_test.py", line 29, in <module>
import cv2
ImportError: No module named 'cv2'

And when I try to run the first example in the tutorial under 'python' this happens:

pi@stereopi:~/stereopi-tutorial $ python 1_test.py
Used camera resolution: 1280 x 480
Scaled image resolution: 640 x 240
Traceback (most recent call last):
File "1_test.py", line 67, in <module>
for frame in camera.capture_continuous(capture, format="bgra", use_video_port=True, resize=(img_width,img_height)):
File "/usr/lib/python2.7/dist-packages/picamera/camera.py", line 1701, in capture_continuous
encoder.start(output)
File "/usr/lib/python2.7/dist-packages/picamera/encoders.py", line 1166, in start
super(PiRawImageMixin, self).start(output)
File "/usr/lib/python2.7/dist-packages/picamera/encoders.py", line 375, in start
self._open_output(output)
File "/usr/lib/python2.7/dist-packages/picamera/encoders.py", line 331, in _open_output
self.outputs[key] = mo.open_stream(output)
File "/usr/lib/python2.7/dist-packages/picamera/mmalobj.py", line 354, in open_stream
stream = BufferIO(stream)
File "/usr/lib/python2.7/dist-packages/picamera/streams.py", line 71, in __init__
'buffer object must be one-dimensional and have unsigned '
ValueError: buffer object must be one-dimensional and have unsigned byte format ("B")

I also tried these commands after this happened in case I had installed picamera the wrong way.

sudo apt-get install python-pip
pip install StereoVision
pip install picamera
sudo apt-get install python3-pip
pip3 install picamera
pip3 install StereoVision

- didn't make any difference to running 1_test.py

I guess I could take a month to learn python and debug the problem, but it would be a lot simpler
if someone could spot a version conflict and show me how to install a working environment... :-)

(Bear in mind in your replies, I'm not a python programmer and don't know my way around the python environment.)

thanks,

G

gtoal
Posts: 9
Joined: Thu Apr 25, 2019 8:58 pm

Re: can't run tutorial example... what did I miss?

Post by gtoal »

After some more messing around, some of which may not have been needed in hindsight (i.e.:

Code: Select all

  sudo apt-get install lightdm
  sudo apt install raspberrypi-ui-mods
  sudo pip3 install opencv-python
  sudo apt-get install libatlas-base-dev libjasper-dev libqtgui4 libqt4-test
  sudo apt install libqt4-test
  sudo apt-get install libgstreamer1.0-0
)

I am getting little farther with the python3 route....

Code: Select all

pi@stereopi:~/stereopi-tutorial $ python3 1_test.py
Used camera resolution: 1280 x 480
Scaled image resolution: 640 x 240
: cannot connect to X server
I suspect that this means these programs require a GUI to run, if so that's a problem because I haven't been able to upgrade the basic CM3+ to a GUI. (I tried but when rebooting, I would log in but it would immediately return to the login screen)

This tells me I will probably only ever get this running by installing SLP, however I'm now on my 9th attempt to download it (4 via Google, 5 via Yandex) and the download always fails some time when I'm not looking, somewhere after at least 1.5Gb has been downloaded. I don't know if it is exceeding the MTBF of my ropey internet connection, or whether my Windows PC is having problems saving files over the 2Gb boundary, or if it is the windows antivirus that is deleting the file immediately after the download completes - as I said I've never managed to be looking at the point when it fails (which since it takes 4 to 8 hours per attempt makes being in front of the computer at the right time quite tricky)

G

User avatar
Realizator
Site Admin
Posts: 900
Joined: Tue Apr 16, 2019 9:23 am
Contact:

Re: can't run tutorial example... what did I miss?

Post by Realizator »

Hi Gtoal,
1. As for OpenCV image download - I can try to put it on Torrent, so you can download it. File size is about 2.7 Gb, and 8Gb micro SD is needed to write it. If you can suggest other options - please let me know, and I will try to use another approach to share this image file. For example, I can cut ZIP archive to several smaller files for you.

2. 4Gb eMMC may be too small to contain GUI Raspbian and all you need for OpenCV. You can fit it in 4 Gb, but it may need some tricks (i.e. efforts and time) from you.

3. While preparing OpenCV image I did these key steps:
- Set Python 3 as a default (alias python='/usr/bin/python3' in .bashrc, as described here)
- pip-install according to pyimagesearch.com article
- after following this guide, follow steps from this comment to fix errors
- install StereoVision and stereopi-tutorial

4. "cannot connect to X server" - yes, all scripts rely on GUI. This is a tutorial scripts, that's why we do it this way.

5. Please do not try to install OpenCV on our S.L.P. Image. Our S.L.P. is optimized for another use cases, and mixing it with OpenCV will force you to solve a lot of unnecessary tasks (read-only FS, small partition size, special edition of raspistill and raspivid and so on).
Eugene a.k.a. Realizator

gtoal
Posts: 9
Joined: Thu Apr 25, 2019 8:58 pm

Re: can't run tutorial example... what did I miss?

Post by gtoal »

Realizator wrote:
Sun Jun 02, 2019 10:59 am
Hi Gtoal,
1. As for OpenCV image download - I can try to put it on Torrent, so you can download it. File size is about 2.7 Gb, and 8Gb micro SD is needed to write it. If you can suggest other options - please let me know, and I will try to use another approach to share this image file. For example, I can cut ZIP archive to several smaller files for you.
I got it in the end (10th attempt!) Unfortunately I then discovered the whole issue about not being able to boot from uSD in the non-Lite compute modules :-( So I started reading about how to write the image to the 4Gb eMMC, but on unzipping stereopi-opencv-20190405.zip I found that the image file was 8Gb :-(
Realizator wrote:
Sun Jun 02, 2019 10:59 am
2. 4Gb eMMC may be too small to contain GUI Raspbian and all you need for OpenCV. You can fit it in 4 Gb, but it may need some tricks (i.e. efforts and time) from you.
I'm starting to realise that :-( I'll have to shrink the fs on the image from 8Gb to 4Gb with resize2fs... Hopefully it will just fit without also having to prepare a compressed filing system for the read-only parts of the OS with squashfs or cramfs...

(Later note: I was able to attach a WD PiDrive (314Gb) to the compute module, and copy off the original mmcblk0 as an image, plus the 8192*512 boot sector separately and the two partitions separately, so between those I ought to be able to construct a bootable file system image to write back to the eMMC... also for non-portable uses of the stereopi, I can mount the pidrive and loop mount a new usr/var/etc on top of the eMMC versions.)
Realizator wrote:
Sun Jun 02, 2019 10:59 am
3. While preparing OpenCV image I did these key steps:
- Set Python 3 as a default (alias python='/usr/bin/python3' in .bashrc, as described here)
- pip-install according to pyimagesearch.com article
- after following this guide, follow steps from this comment to fix errors
- install StereoVision and stereopi-tutorial

4. "cannot connect to X server" - yes, all scripts rely on GUI. This is a tutorial scripts, that's why we do it this way.
I think I did manage to get the tutorial installed but since it relies on X and I can't get the GUI to work, I'm a bit stuck. (startx exits immediately without any helpful log messages to say why). I even tried running X on another machine and trying the scripts remotely but didn't succeed :-(
Realizator wrote:
Sun Jun 02, 2019 10:59 am
5. Please do not try to install OpenCV on our S.L.P. Image. Our S.L.P. is optimized for another use cases, and mixing it with OpenCV will force you to solve a lot of unnecessary tasks (read-only FS, small partition size, special edition of raspistill and raspivid and so on).
OK. Looks like my best bet is to work from the 8Gb image and try to shrink it to fit on the 4Gb eMMC. I wish this had been better explained on the crowdfunding site as I would have known to buy the CM lite to begin with.

I suppose a supported 4Gb image from the project is too much to ask for? :-)

Since I do have the basic stereo cameras working under raspbian, I may decide just to skip the tutorials etc and stick with what I've got that works. I have enough to do my current project, which is to embed the system in an old stereo camera chassis so I can use it as a portable stereo video camera. (basically re-doing https://www.instructables.com/id/Retro-Pi-Cam/ in stereo)
stereopicam.png
stereopicam.png (145.84 KiB) Viewed 7194 times
LATE NOTE: Gordian knot solution. I've just ordered a CM3 Lite ... I'ld rather blow $25 than another day trying to make this work the hard way...

G

User avatar
Realizator
Site Admin
Posts: 900
Joined: Tue Apr 16, 2019 9:23 am
Contact:

Re: can't run tutorial example... what did I miss?

Post by Realizator »

Hi Gtoal,
I did some tricks for you:
1. I wrote OpenCV image to 8 Gb micro SD
2. I connected it to Ubuntu computer and shrinked partition to ~3.5Gb, and recorded image file
3. This image was uploaded to CM3 (non +, non Lite) with 4 Gb eMMC
4. After boot on CM3, I used raspi-config to expand partition to use all eMMC space
5. You can download OpenCV 4Gb eMMC image here (1.67Gb size)

It's about 500 Mb of free space on it, so you should control free space to avoid eMMC overflow.

I really like your project with installing digital contend in old-fashioned camera! Cool! :) I think adding a "make photo button" on GPIO and connecting to your camera button is a good option!

As for CM3 Lite - I mentioned in several places (and updates), that CM Lite edition is better option as you are working with micro SD card. It is easier and more comfortable. Looks like my description has not enough accent, thus this information still unnoticed by users. And I think your CM3 Lite order is a good solution.
Eugene a.k.a. Realizator

gtoal
Posts: 9
Joined: Thu Apr 25, 2019 8:58 pm

Re: can't run tutorial example... what did I miss?

Post by gtoal »

Appreciate that you built an image for me (and other 4Gb CM users)! I'll try it today.

Спаси́бо большо́е!

Graham

User avatar
Realizator
Site Admin
Posts: 900
Joined: Tue Apr 16, 2019 9:23 am
Contact:

Re: can't run tutorial example... what did I miss?

Post by Realizator »

Пожалуйста! :-)
Right now I'm uploading this image to Google disk, so you can choose download source.
Eugene a.k.a. Realizator

gtoal
Posts: 9
Joined: Thu Apr 25, 2019 8:58 pm

Re: can't run tutorial example... what did I miss?

Post by gtoal »

While waiting for the mail-order CM3lite to arrive, I decided to have a go at writing the 4Gb image to the eMMC in the CM3 (non-lite).

(The module has printed on the back "Raspberry Pi Compute Module 3" "2015 Version 1.0")

I unplugged the power supply, the keyboard/monitor, the cameras - just leaving the CM in the stereopi. Then I added a jumper to the two pins (btw the web page image has 3 pins :-) )

"Under Windows, run rpiboot.exe. After that you will see a new disk appear in the file manager. That's your eMMC. Now you can write a Linux image onto it the same way you would with a micro SD card."

I installed rpiboot - apparently successfully.

When I run rpiboot, I get the message: "Waiting for BCM2835/6/7"

I've started rpiboot both before powering up stereopi and after, I've tried it as regular user and under 'run as administrator', and I've tried several usb cables. I can't think of anything else to try (other than wait for the mail-order CM3 lite to arrive)

At no point have I seen any windows messages about finding new devices when I plugged in the stereopi.

Any suggestions?

Is your driver signed? I'm looking at https://revolution.kunbus.com/forum/vie ... ?f=6&t=851 and https://www.drivereasy.com/knowledge/di ... 10-easily/ - if the driver isn't signed, that could explain it.

By the way, my CM3-lite just turned up, and I have it working now! (I'll revisit the other CM3 later to get to the root of the problem, but for this evening I'll be occupied having fun with the StereoPi software...)

And finally... after now having tried both the 4Gb image and the 8Gb image, I've realised that they both hold only the tutorial examples - but not the SLP! That's yet another download that I'm doing now :-) At least this one is not so large... (800Mb zipped)

thanks

Graham

Post Reply