opencv調用網路攝影機

來源:互聯網
上載者:User
#include <cstdio>#include <highgui.h>int main(){IplImage *pImg = NULL;CvCapture *cap = cvCaptureFromCAM(0);char fileName[100];char key;int count = 0;while(1){pImg = cvQueryFrame(cap);cvFlip(pImg, NULL, 1); //水平翻轉映像,像照鏡子一樣,不想要這個效果可以去掉此句key = cvWaitKey(50);if(key == 27) break; //按ESC鍵退出程式if(key == ' ')       //按空格鍵拍照{sprintf(fileName, "Picture %d.jpg", ++count); //組建檔案名cvSaveImage(fileName, pImg);cvXorS(pImg, cvScalarAll(255), pImg);         //將拍到的映像反色(閃一下形成拍照效果)cvShowImage("Camera",pImg);cvWaitKey(200); //反色映像顯示ms}cvShowImage("Camera",pImg);}cvReleaseCapture(&cap);return 0;}

藉助於百度雲,我們可以很好地實現拍照雲上傳功能。

#include <stdio.h>#include <highgui.h>#include <windows.h>#include <stdlib.h>#include <time.h>#pragma warning (disable : 4996)int main(){IplImage *pImg = NULL;CvCapture *cap = cvCaptureFromCAM(0);char fileName[100];char key;time_t t;char temp[64];while(true){pImg = cvQueryFrame(cap);cvFlip(pImg, NULL, 1); //水平翻轉映像,像照鏡子一樣,不想要這個效果可以去掉此句key = cvWaitKey(50);if(key == 27){break; }if(key == ' '){t = time(NULL);strftime( temp, sizeof(temp), "%Y%m%d%H%M%S", localtime(&t));sprintf(fileName, "d:\\百度雲\\data\\%s.jpg", temp); //按日期組建檔案名printf(fileName, "d:\\百度雲\\data\\%s.jpg", temp);printf("\n");cvSaveImage(fileName, pImg);cvXorS(pImg, cvScalarAll(255), pImg);  //將拍到的映像反色(閃一下形成拍照效果)cvShowImage("Camera", pImg);cvWaitKey(200); //反色映像顯示ms}cvShowImage("Camera", pImg);}cvReleaseCapture(&cap);return 0;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.