Skip to main content

OpenCV Docker Image and use

Open CV

Install docker mage

run
$ docker ps
$ docker start 0c5f0bc9b04c
$ docker ps -a

We need to go Self terminal not SSH terminal

$ gksudo
open a bog
and type
lxterminal

Python and OpenCV.
Alright, now we can finally start writing some code!
Open up a new file, name it test_image.py , and insert the following code:
We’ll start by importing our necessary packages on Lines 2-5.
From there, we initialize our PiCamera object on Line 8 and grab a reference to the raw capture component on Line 9. This rawCapture  object is especially useful since it (1) gives us direct access to the camera stream and (2) avoids the expensive compression to JPEG format, which we would then have to take and decode to OpenCV format anyway. I highly recommend that you use PiRGBArray  whenever you need to access the Raspberry Pi camera — the performance gains are well worth it.
From there, we sleep for a tenth of a second on Line 12 — this allows the camera sensor to warm up.
Finally, we grab the actual photo from the rawCapture  object on Line 15 where we take special care to ensure our image is in BGR format rather than RGB. OpenCV represents images as NumPy arrays in BGR order rather than RGB — this little nuisance is subtle, but very important to remember as it can lead to some confusing bugs in your code down the line.
Finally, we display our image to screen on Lines 19 and 20.
To execute this example, open up a terminal, navigate to your test_image.py  file, and issue the following command:
If all goes as expected you should have an image displayed on your screen:
Figure 6: Grabbing a single image from the Raspberry Pi camera and displaying it on screen.
Figure 6: Grabbing a single image from the Raspberry Pi camera and displaying it on screen.
Note: I decided to add this section of the blog post after I had finished up the rest of the article, so I did not have my camera setup facing the couch (I was actually playing with some custom home surveillance software I was working on). Sorry for any confusion, but rest assured, everything will work as advertised provided you have followed the instructions in the article!

Step 6: Accessing the video stream of your Raspberry Pi using Python and OpenCV.

Alright, so we’ve learned how to grab a single image from the Raspberry Pi camera. But what about a video stream?
You might guess that we are going to use the cv2.VideoCapture  function here — but I actually recommend against this. Getting cv2.VideoCapture  to play nice with your Raspberry Pi is not a nice experience (you’ll need to install extra drivers) and something you should generally avoid.
And besides, why would we use the cv2.VideoCapture  function when we can easily access the raw video stream using the picamera  module?
Let’s go ahead and take a look on how we can access the video stream. Open up a new file, name it test_video.py , and insert the following code:
This example starts off similarly to the previous one. We start off by importing our necessary packages on Lines 2-5.
And from there we construct our camera  object on Line 8 which allows us to interface with the Raspberry Pi camera. However, we also take the time to set the resolution of our camera (640 x 480 pixels) on Line 9 and the frame rate (i.e. frames per second, or simply FPS) on Line 10. We also initialize our PiRGBArray  object on Line 11, but we also take care to specify the same resolution as on Line 9.
Accessing the actual video stream is handled on Line 17 by making a call to thecapture_continuous  method of our camera  object.
This method returns a frame  from the video stream. The frame then has anarray  property, which corresponds to the frame  in NumPy array format — all the hard work is done for us on Lines 17 and 20!
We then take the frame of the video and display on screen on Lines 23 and 24.
An important line to pay attention to is Line 27: You must clear the current frame before you move on to the next one!
If you fail to clear the frame, your Python script will throw an error — so be sure to pay close attention to this when implementing your own applications!
Finally, if the user presses the q  key, we break form the loop and exit the program.
To execute our script, just open a terminal (making sure you are in the cv  virtual environment, of course) and issue the following command:

Comments

Popular posts from this blog

Raspberry pi Ser2Net Install

sudo apt-get install ser2net sudo nano /etc/ser2net.conf % change last lines to 2000:raw:600:/dev/ttyAMA0:57600 8DATABITS NONE  1STOPBIT banner sudo /etc/init.d/ser2net restart sudo nano /etc/inittab % add hash to this line #T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100 sudo nano /boot/cmdline.txt % delete references to ttyAMA0 % "console=ttyAMA0,115200 kgdboc=ttyAMA0,115200" sudo shutdown -r now

Modem Connection with raspberry py

Aim : Set up the  Raspberry Pi  as a wireless router using the Raspbian OS. The internet connection will be provided by a  Huawei E303  USB 3g dongle on the safaricom network in Kenya, though the setup should be similar on most Huawei dongles and 3g networks. The wireless access point will be provided by an  Edimax Nano USB Wifi adapter . Power Source -------->RPI ----> Powered USB HUB -----> 3g Dongle                                            |                                            |                                          Edimax                       ...