Stream live camera feed from RPI compute module to RPI 3 - c++

I'm developing a portable hardware/software application to use 2 cameras in a stereo vision configuration, and process the raw data for information to output.
For this reason I have a Raspberry pi Compute module kit, and a Raspberry pi 3.
The compute module kit will operate the two cameras
The pi 3 will run the code as it has the computational power
OpenCV (C++) is the preferred CV package
As this is a portable application, internet based streaming is not a suitable option.
I've not had time to play around with the GPIO pins, or find a method of streaming the two camera feeds from the compute module to the pi 3.
How would you suggest I proceed with this? Has anyone performed such a project? What links can you provide to help me implement this?
This is for a dissertation project, and will hopefully help in the long run when developing as a full prototype.
Frame Size: 640x480
Frame Rate: 15 fps
The cameras are 5cm apart from each other

Updated Answer
I have been doing some further tests on this. Using the iperf tool and my own simple TCP connection code as well, I connected two Raspberry Pis directly to each other over wired Ethernet and measured the TCP performance.
Using the standard, built-in 10/100 interface on a Raspberry Pi 2 and a Raspberry Pi 3, you can achieve 94Mbits/s.
If, however, you put a TRENDnet USB3 Gigabit adaptor on each Pi, and repeat the test, you can get 189Mbits/s and almost 200 if you set the MTU to 4088.
Original Answer
I made a quick test - not a full answer - but more than I can add as a comment or format correctly!
I set up 2 Raspberry Pi 2s with a wired Ethernet connection. I took a 640x480 picture on one as a JPEG - and it came out at 178,000 bytes.
Then, on the receiving Pi, I set up to receive 1,000 frames. Like this:
#!/bin/bash
for ((i=0;i<1000;i++)); do
echo $i
nc -l 1234 > pic-${i}.jpg
done
On the sending Pi, I set up to transit the picture 1,000 times:
for ((i=0;i<1000;i++)) ; do nc 192.168.0.65 1234 < pipic1.jpg ;done
That took 34 seconds, so it does 33 fps roughly but it stuttered a lot because of writing to the filesystem and therefore SD card. So, I removed the
nc -l 1234 > pic-${i}.jpg
and didn't write the data to disk - which is what you will need as you are writing to the screen, as follows:
nc -l 1234 > /dev/null

Related

Mimik Smart-car-use-case -- Postman Simulation

I am trying to solve the smart-car solution, I have a situation as below
Device 1 and Device 2 are Raspberry Pi OS device
Device 1 captured an image using the camera attached to it, and Device 2 finds the Device 1 and should be capable to view the captured image generated by the Device 1.
In the above situation since both the devices are taken as Raspberry Pi OS device,
1. In which device should I download Postman and its associated collection and environment?
I tried to install postman in one of the Raspberry Pi OS devices, but got some error as below.
2. Since it showed some support/stable issue, Is there any other Pi image that is compatible with Postman?
Please look at official documentation from postman to get their recommendation on which image to use that is stable.

Pi 3 USB USB Microphone; accessing programmtically in C/C++

I am doing a speech processing project with a Raspberry Pi 3 (running Raspbian) using a USB Microphone. I can see the Microphone show up as a selectable audio device for the Pi and it produces/captures sound perfectly.
I cannot figure out how to use this in my code; I have done a ton of research regarding this and have found some tutorials but nothing that making sense. I come from more of a hardware background and have done something like this with controllers where I hook up an actual Mic and process the Analog Signal into Digital on IO Pins; I am so frustrated with this that I am about to pump data over from an Arduino using a Mic and A2D conversion.
-------------------------------------------------------My questions----------------------------------------------------
1) I want to know how to access a USB data stream or USB device in C or C++. My Linux abilities are not the best. Do I open a Serial Connection or open a filestream in "/dev/USB/...."? Can you provide a code example?
2) Regardless of the fidelity of the USB Mic Input, I want to know how to access its Input in C/C++. I have been looking at ALSA but cannot really understand a lot of its complexity. Is there something that gives me access to a raw input signal on the USB Port that I can process ( where I extrapolate out frequency, amplitude, etc.)?
I have already gone through a lot of the similar posts on here. I am really stuck on this one. I 'm really looking to understand what is going on from the OS perspective; I'll use a library given but I want to understand how it works.
Thanks!
So an update:
So I did all of my code in C with some .sh scripts. I went ahead and figured out how to use the Alsa asoundlib (asound.h specifically). As of now, I am able to generate and record sound via USB Mic/Headset with my Pi 3. Doing so is rather arduous but here is a useful link (1).
For my project, I also found a CMU tutorial/repos for their PocketSphinx Audio Recognition Device at link (2) and video link (3). This project utilizes the Alsa asoundlib as well and was a great help for me. It takes a while to download and you need to crawl through its .sh scripts to figure out its gcc linking. But I am able to now give audio cues which are interpreted by my Pi 3 and pushed to speaker output and GPIO pins.
LINKS(1)http://www.alsa-project.org/alsa-doc/alsa-lib/_2test_2pcm_8c-example.html
(2)https://wolfpaulus.com/embedded/raspberrypi2-sr/
(3)https://www.youtube.com/watch?v=5kp5qpwVh_8

Raspberry pi3: C++ serial communication not working properly (Raspberry pi was working!)

I have a Raspberry PI B+ with a C++ application that is able to communicate with an Arduino. I'm able to read, write, serial connection perfeclty stable.
Now, I bought a Raspberry PI3 in order to have more performances and wifi integrated.
After a lot of time spent, I got the QT application working again but the serial communication wouldn't work.
I connected the serial monitor of Arduino IDE and checked that with RPI 1 it is working fine, and I saw all messages sent following my protocol, so I'm sure that I can analyze what I'm writing out of Raspberry P3.
Unfortunaltely, I receive only weird characters:
I tried different baudrate, for example 115200 and 9600 (expected baudrate!) but the result is different but equally wrong.
I would like to report what I did in my Raspberry P3:
I disabled the serial port for the console (as I understood on the web)
This settings would modify automatically the option:
enable_uart=0
it's strange because in the web I found who is suggesting to enable, who clearly write that it should be disabled because refers to "console over serial".
Then, I added some lines (you can see into red shape) in order to move the bluetooth handling in the miniuart, fixing the cpu frequency to 250 and fixing the default baudrate to 9600.
Then, I disable the bluetooth with this command:
I'm really not sure of that but.. something suggested in some posts.
Finally, this is the setup in my QT c++ application:
Where I changed the name of the port to "ttyS0", (same "serial1").
So.. what I would like to achieve is setup my pi3 serial communication as was working with piB+, connected on same pins GPIO14 and GPIO15.
Doesn't matter to bluetooth, I will not use it.
What I miss or made wrongly?
The PINOUT of Raspberry PI3 seems equal to PINOUT of Raspberry PI B+:
And the PINOUT of Raspberry B+ is:
But I found one interesting thing:
It seems the configuration somehow is wrong because GPIO14 and GPIO15 are both INPUTS !!
I finally fixed!
As I wrote, I found many suggestions on the web but quite often discordant.. so I will report here how I setup my Raspberry p3 in order to work fine.
1) Upgraded my system
sudo apt-get update
sudo apt-get dist-upgrade
2) Enabled the UART console
sudo raspi-config
Advanced options --> serial:
Note: it will automatically set 1 the enable_uart in the file config.txt.
3) Edit config.txt
sudo nano /boot/config.txt
I added basically one line in order to disable the bluetooth port (not used in my case)
I also removed the limitation of cpu frequency to 250, found many times as hint in forums, as you can see it's commented (#).
You can also see the setup of "enable_uart=1" done with raspi-config interface.
4) Edit file cmdline.txt
sudo /boot/cmdline.txt
I removed the piece of string where there was something like:
.... console=serial0,115200 ....
5) Application refers to serial0
6) DONE !
I Hope this step-by-step guide works for someone else or in general will be helpful.

How to get a DHT22/AM2302 sensor to work with MCP23017 I2C Port Expander

I am building out a monitoring and automation system for my various greenhouses in the garden. Due to the number of devices that need to be controlled and monitored rather than purchasing additional Raspberry PIs I decided to go with a GPIO port expander and make use of the existing Raspberry PI hardware.
I have however managed to hit a "wall" when it comes to reading the DHT22 Temperature and Humidity sensor when I connect it up via the MCP23017. I know I have the MCP23017 connected correctly as I am able make LEDs flash and relay switches turn on and off.
None of these require reading data from the device connected though and this where I am running into the problem and would really appreciate any help or advice.
I am running a Revison 2 Raspberry PI A, sudo i2cdetect -y 1 shows MCP23017 connected to 0X20.
I am using Python 2.7 for the coding, using the Adafruit_DHT module and for addressing the MCP23017 I am using the wiringpi2 module. Although I am open to other suggestions here with regards to using wiringpi2.
The Adafruit_DHT uses the following syntax to connect to and retrieve information from the sensor:
import Adafruit_DHT
sensor = Adafruit_DHT.DHT22
pin = 7
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
The above works fine when connecting directly to one of the "standard" GPIO ports. However I have not worked out how to address the additional new GPIO ports in this same manner i.e.
I have tried the following with no success:
import Adafruit_DHT
import wiringpi2
wiringpi2.wiringPiSetupGpio()
wiringpi2.mcp23017Setup(65,0x20)
for n in (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16):
humidity, temperature = Adafruit_DHT.read_retry(sensor22, wiringpi2.digitalRead(n+64))
print n, humidity, temperature
So the above cycles through each new port, however I don't get any results back, as I say if I connect the device directly the GPIOs on the PI is works fine. I suspect the issue with how I am telling the driver which PIN to use.
I would really appreciate any advice or help on this issue. As I said I am open to other ideas on how to use this DHT22 with the MCP23017.

how to stream video from a camera connected to Raspberry Pi to a PC on the same network?

I am going to connect:
a: a wifi dongle to Raspberry Pi and make an Ad Hoc network
b: a raspberry pi camera to the raspberry pi
I want to connect to the RPi's ad hoc network from my PC. Once the PC and the RPi are on the same network,an application on the PC should be able to stream video from the camera and be able to control the GPIO pins on the Raspberry. My problem is that I don't know how to get started with the application.
Can anyone tell me what topics to read,and what libraries to use for streaming?anything that can help me at all will be highly appreciated as I am completely in the dark right now.I am comfortable with programming in C++ so the application will naturally be in C++.
Thanks.
a possible starting point for the video streaming could be mjpg-streamer
https://code.google.com/p/mjpg-streamer/
I used this without problem to stream video from the pi so that I could view it in a browser on a different PC on the same network.
I did it before using mjpg-streamer and also made a video show the way to do.
Check it here
Easiest way to stream Raspberry Pi Camera Module