Run OpenCV script on start with imshow - python

I have an OpenCV/python script running at my Raspberry Pi which reads the camera and shows the stream on the RCA monitor connected to the Pi.
Now I want the script to be loaded on boot. I already tried a cronjob #reboot, the /etc/rc.locale, /etc/profile and ~/.bash_profile.
I see the red light of the camera turning on every time, but the image won't be shown. Is there any solution to run the script? (I have no external input devices connected)
Thank you!

I know its quite an old thread, but I thought you might be still interested in a solution that worked for me. Hopefully, that can help you as well:
Raspberry Pi - Autostart OpenCv-Script - Error with cv::imshow()
In short: You most likely have problems with the DISPLAY / XAUTHORITY environment variable.

Related

Raspberry Pi: Enable or disable touch screen from Python script

I am working with Raspberry Pi 4 B, 8 gb RAM and Raspbian OS. I am having 7" touch screen attached to PI.
In my project, I want to make touch screen sleep if there is no activity detected for 5 mins from the Python script (just to save some power). Is there any shell command I can use in the Python script?
There is the option in config.txt of "disable_touchscreen=1" which will stop the Pi polling the controller board for touch input. It also doesn't start the firmware side of the touchscreen input driver, which should stop the Linux side loading either. The display side will work exactly as before.
This file is normally accessible as /boot/config.txt from raspbian OS.
You can read config.txt and modify using following python code
import ConfigParser
config_parser = ConfigParser.ConfigParser()
config_parser.read('config.txt')

Raspberry pi:enable camera module

I have attached an usb camera with raspberry pi and also enable it using sudo raspi-config command . I rebooted the raspberry pi after enabling it, but it doesn't enable - so getting error (error is..mmal: Camera is not detected. Please check carefully the camera module is installed correctly)
When run command (raspistill -o image.jpg) to capture an image, I have also run update and upgrade command to update raspberry pi but doesn't solve problem.
And main thing when I run ffnpng -i /dev/video video.avi, it records video so camera working so why this error coming? And what is the solution for that.
Is there any other way or command to cature image? plz help me. Thank u in advance.
Have you installed the fswebcam module? You can get it using:
sudo apt-get install fswebcam
Images are taken using the command fswebcam <image_name>.jpg
A full tutorial can be found here from raspberrypi.org.
It looks like the problem is the connection between camera module and Raspberry PI CSI interface. Check if the CSI cable is correctly connected to CSI interface on the Raspberry PI board or try to unplug camera cable and plug it again.
raspistillyuv and raspistill are official image capturing programs for the camera module: link
USB cameras are not mounted under mmal (Only CSI). Try running v4l2-ctl --list-devices to see if your camera is mounted correctly. You will see there is a /dev/videoX like string under your camera if it's mounted correctly. Use that X value to access the camera.
As an example, in OpenCV(Python) you can capture an image as bellow,
import cv2
cap = cv2.VideoCapture(X)
ret, frame = cap.read()
cv2.imwrite("image_name.jpg",frame)
cap.release()

Run PyGame program without booting to Desktop Raspberry Pi

I am using the PiTFT display for the Raspberry Pi, and I want to run my PyGame (Python) program without booting to the Desktop.
The reason I want to do this is because it will mean less RAM usage, and that is pretty important on a Raspberry Pi.
This has been asked before, but none of the answers are up to date, or else never worked in the first place.
I'm not exactly clear what problem you're having, but this should be fairly straightforward.
I add this at the top of my pygame scripts when using the PiTFT screen (none of my Pis use the desktop environment):
import os
# Tell the RPi to use the TFT screen and that it's a touchscreen device
os.putenv('SDL_VIDEODRIVER', 'fbcon')
os.putenv('SDL_FBDEV' , '/dev/fb1')
os.putenv('SDL_MOUSEDRV' , 'TSLIB')
os.putenv('SDL_MOUSEDEV' , '/dev/input/touchscreen')
Then you just need to make sure your pi doesn't boot into the desktop environment. You can do that by running:
sudo raspi-config
and changing the relevant setting.

Pycharm, OpenCV execute on remote server and display Image locally

I set up PyCharm for remote debugging according to this tutorial on CodeProject
http://www.codeproject.com/Tips/987276/Remote-Programming-of-RaspberryPi-using-PyCharm
I am now wondering if it is possible to execute a Python Script with the help of PyCharm on the RaspberryPI and receive the output in PyCharm. Specifically I want to do some image processing and display the image with the help of OpenCV. It would be great to get the image displayed on my Windows machine, not on the Pi.
Another usecase, I want to create some matplot figure, execute the script on the pi and show the Output back in PyCharm on my Windows machine.
Is this possiple?
Kind Regards
You can do this using OpenCV Image Viewer Plugin. Debug you program using remote interpreter in Pycharm, stop at the breakpoint and choose "View as image".
https://plugins.jetbrains.com/plugin/14371-opencv-image-viewer
Disclaimer: I'm an author of this plugin

Uploading Motion Files to Google Drive using Raspbian and Raspberry Pi

I've been playing around with Motion on my Rapsberry Pi running Raspbian and came across this post that sounded like fun to do.
I've been trying to tweak the steps he lists to have it work with Raspbian, and as far as I know I should be good. I installed GData using "sudo apt-get install python-gdata" And then I put the uploader.py and uploader.cfg files in /etc/motion and changed the motion.confg file to have the line
on_movie_end /etc/motion/uploader.py /etc/motion/uploader.cfg %f
Am I missing something? Theoretically this should work on Raspbian right? What else has to be done?
Thanks
I have been following the guides you have referred to get this working on Raspbian and I had the same problem; Motion seems to work but the script never executes.
However, when i tried to run the script directly I got a permission error.
I ran the following to make the script executable.
chmod a+x /etc/motion/uploader.py
now it uploads the videos to Google drive (no emails though?)
hope this helps,
This isn't a direct answer to your question, but it might be a away of getting files uploaded to google drive in an easier way.
Have you had a look at grive, its a linux utility which can be used to sync a folder on your raspberry pi with a folder on google drive.
See this link for more info on how to setup and use grive on a raspberry pi.
http://www.stuffaboutcode.com/2013/03/raspberry-pi-google-drive-grive.html
I also struggled with it quite a bit and this is what helped. First try to run this from terminal:
/etc/motion/uploader.py /etc/motion/uploader.cfg /
Here you put the absolute path to your file you want to upload.
Try to run it, and if it asks you for a password you know you have a permission problem and need to change permissions so that it does not require the password to execute.
Try again. If it works then it will also work if you use this in uploader.cfg:
on_movie_end /etc/motion/uploader.py /etc/motion/uploader.cfg %f
Do not forget to uncomment this line! This sounds silly but it took me some time to realize it, i.e. delete ; that is in front of on_movie_end.
Another issue I had was the movie encoding. Only mpeg4 really worked for me.

Categories

Resources