Created
April 22, 2011 18:26
-
-
Save mathnathan/937304 to your computer and use it in GitHub Desktop.
Video Networking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# include "highgui.h" | |
# include "cv.h" | |
# include <stdio.h> | |
# include <vector> | |
# include <string> | |
using namespace cv; | |
int main( int argc, char** argv ) { | |
Mat frame; | |
vector<unsigned char> buffer; // Store each frame in this buffer | |
string extension = ".jpg"; // Here you choose which extension you want (jpeg has compression) | |
VideoCapture VidCap(0); // Start capturing from device 0 | |
if( !VidCap.isOpened() ) { | |
printf( "ERROR: Device 0, was not opened successfully\n" ); | |
return 0; | |
} | |
VidCap >> frame; // Grab the first frame | |
while( !frame.empty() ) { | |
// Image Encoding already does compression for you!! | |
if( !imencode( extension, frame, buffer ) ) { | |
printf( "ERROR: Problem encoding image from Device 0\n" ); | |
return 0; | |
} | |
/* ---------------------- | |
Here you do your networking magic and | |
send the buffer to computer B | |
---------------------- */ | |
imshow( "Logitech Webcam", frame ); | |
char c = waitKey( 33 ); | |
if( c == 27 ) break; // press esc to exit | |
VidCap >> frame; // Grab the next frame | |
buffer.clear(); // Flush the buffer | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment