raspberry pi (樹莓PI)使用socket向PC發送視頻流

來源:互聯網
上載者:User

標籤:des   blog   http   color   io   os   ar   使用   java   

安裝boost
sudo apt-get install libboost1.50-all

 

測試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; }

 編譯

g++ -std=c++0x -lstdc++ -lboost_regex it.cpp

 運行

./a.out

 

安裝opencv
apt-cache search opencvsudo apt-get install libopencv-dev

 

測試opencv

我使用的webcam型號是羅技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, 30, 3);imwrite("frame.jpg",frame);imwrite("edges.jpg",edges);return 0;}

 編譯

 g++ -std=c++0x -lstdc++ -lopencv_highgui -lopencv_video -lopencv_core -lopencv_calib3d -lopencv_contrib -lopencv_imgproc  2.cpp

 

編寫傳輸映像代碼

 

#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(100);if (c==27){break;}frame = (frame.reshape(0,1)); // to make it continuousstd::string message((char *)frame.data,230400); /* the size of mat data is 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;}

 

編譯

 

 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 (樹莓PI)使用socket向PC發送視頻流

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.