Skip to content

Instantly share code, notes, and snippets.

@nsantorello
Created October 22, 2013 16:22
Show Gist options
  • Save nsantorello/7103663 to your computer and use it in GitHub Desktop.
Save nsantorello/7103663 to your computer and use it in GitHub Desktop.
OpenCV stream from raspberry pi
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
#include <stdio.h>
using namespace std;
using namespace cv;
int main( int argc, const char** argv )
{
cout << "Starting..." << std::endl;
CvCapture* URL= cvCreateFileCapture("/path/to/my/pipe/here");
cout << "loaded pipe" << std::endl;
Mat image;
while (true) {
image = cvQueryFrame(URL);
if(! image.data ) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}
namedWindow( "Display window", CV_WINDOW_AUTOSIZE );// Create a window for display.
imshow( "Display window", image ); // Show our image inside it.
cvWaitKey(1); // Wait for a keystroke in the window
}
return 0;
}
  1. Build display.cpp
  2. Set up pipe on Linux VM
  3. Run display application
  4. Run proxy/passthrough on Mac
  5. Start streaming from Raspberry Pi
# On Linux VM
rm my_pipe; mkfifo my_pipe; nc -q 5 -l 5001 > my_pipe
# On Mac
nc -l 5002 | nc <your VM's ip> 5001
# On Raspberry Pi
# ssh pi@ipaddress
# password is 'raspberry'
# -t 0 => stream infinitely. (t is in milliseconds)
# -fps 12 => stream at 12 fps
# -o - => output to stdout
raspivid -fps 12 -t 0 -o - | nc <your Mac's ip> 5002
g++ display.cpp -lopencv_core -lopencv_highgui -o display
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment