Install boost
sudo apt-get install Libboost1.50-all
Test boost
1.cpp
#include <string> #include <boost/regex.hpp> int main () { std::string text ("A fat cat sat on the mat");
boost::regex Re ("\\w+"); Boost::sregex_token_iterator I (Text.begin (), Text.end (), re, 0); Boost::sregex_token_iterator end; for (; I! = end; ++i) { std::cout << *i << '; } Std::cout << Std::endl; return 0; }
Compile
g++-std=c++0x-lstdc++-lboost_regex It.cpp
Run
./a.out
Installing OPENCV
Apt-cache Search Opencvsudo apt-get Install Libopencv-dev
Test OpenCV
The webcam model I use is Logitech c270
2.cpp
#include <opencv2/highgui/highgui.hpp> #include <opencv2/imgproc/imgproc.hpp> #include <opencv2/core /core.hpp>using namespace Cv;int Main () {videocapture cap (0); if (!cap.isopened ()) {return-1;} Mat frame; Mat Edges;cap>>frame;cvtcolor (frame, edges, cv_bgr2gray); Gaussianblur (edges, edges, Size (7,7), 1.5, 1.5); Canny (edges, edges, 0, 3), Imwrite ("Frame.jpg", Frame), Imwrite ("edges.jpg", edges); return 0;}
Compile
g++-std=c++0x-lstdc++-lopencv_highgui-lopencv_video-lopencv_core-lopencv_calib3d-lopencv_contrib-lopencv_ Imgproc 2.cpp
Writing Transfer Image code
#include <iostream> #include <boost/array.hpp> #include <boost/asio.hpp> #include "opencv2/highgui/ Highgui.hpp "#include" opencv2/imgproc/imgproc.hpp "#include <opencv2/core/core.hpp> #include <ctime># Include <string>using boost::asio::ip::tcp;using namespace std;using namespace cv;int main (int args, char *argv[]) {videocapture cap (0); /* Open Webcam */if (!cap.isopened ()) {return-1; } Mat Frame;cap.set (Cv_cap_prop_frame_width, 320); /* Set width */cap.set (cv_cap_prop_frame_height, 240); /* Set height */try{boost::asio::io_service io_service;tcp::endpoint end_point (boost::asio::ip::address::from_ String (argv[1]), 3200); Tcp::socket socket (io_service); Boost::system::error_code Ignored_error;socket.connect (End_point); while (true) {Cap>>frame;char c= (char) Waitkey (+); if (c==27) {break;} frame = (Frame.reshape (0,1)); To make it continuousstd::string message ((char *) frame.data,230400); /* The size of the mat datais 320*240*3 */socket.write_some (boost::asio::buffer (message), ignored_error);cout<< "send image Finished" < <endl;} Socket.close ();} catch (std::exception& e) {std::cerr << e.what () << Std::endl;} return 0;}
Compile
g++-std=c++0x-lstdc++-lopencv_highgui-lopencv_video-lopencv_core-lopencv_calib3d-lopencv_contrib-lopencv_ Imgproc -lboost_system -lboost_thread -lpthread 3.cpp
Raspberry Pi (Raspberry Pi) sends a video stream to the PC using the socket