Advertisement
MrPoxipol

OpenCV cURL FTP

Feb 1st, 2014
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.87 KB | None | 0 0
  1. #include <opencv2/highgui/highgui.hpp>
  2. #include <curl/curl.h>
  3.  
  4. #include <iostream>
  5. #include <string>
  6.  
  7. using namespace std;
  8. using namespace cv;
  9.  
  10. size_t uploadImage(void* ptr, size_t size, size_t nmemb, void* stream)
  11. {
  12.     cout << "Upload started.\n";
  13.     size_t ret = 0;
  14.     ret = fread(ptr, size, nmemb, (FILE*)stream);
  15.     cout << "RET: " << ret << endl;
  16.     return ret;
  17. }
  18.  
  19. int main()
  20. {
  21.     VideoCapture cap(0); // Domyślna kamerka (usb w laptopie - to ta nad matrycą)
  22.     if(!cap.isOpened())  // Jeśli nie udało się otworzyć, kończ program
  23.     {
  24.         cout << "Cannot open the video cam" << endl;
  25.         return -1;
  26.     }
  27.  
  28.     // Rozmiar obrazu z kamerki
  29.     double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH);
  30.     double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT);
  31.     cout << "Frame size : " << dWidth << " x " << dHeight << endl;
  32.  
  33.     /* Połączenie z serwerem */
  34.     CURL* curl = curl_easy_init();
  35.     curl_easy_setopt(curl, CURLOPT_READFUNCTION, uploadImage);
  36.     curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
  37.     curl_easy_setopt(curl, CURLOPT_URL, "ftp://sds");
  38.     curl_easy_setopt(curl, CURLOPT_USERNAME, "admin@");
  39.     curl_easy_setopt(curl, CURLOPT_PASSWORD, "assa");
  40.  
  41.     Mat frame;
  42.     bool bSuccess = cap.read(frame); // Odczytaj dane ze zdjęcia
  43.  
  44.     if(!bSuccess) // Jeśli siadło, odklei się
  45.     {
  46.         cout << "Cannot read a frame from video stream" << endl;
  47.         return -1;
  48.     }
  49.  
  50.     vector <uchar> buffer; // Buffor do odczytania przekonwerterowanych danych (do formatu np. JPEG)
  51.     imencode(".jpg", frame, buffer); // Zapis do JPEG (dobra kompresja stratna)
  52.     curl_easy_setopt(curl, CURLOPT_READDATA, reinterpret_cast <char*>(buffer[0]));
  53.  
  54.     CURLcode res = curl_easy_perform(curl);
  55.     if(res != CURLE_OK)
  56.         fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
  57.  
  58.     return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement