資源簡介
基于QT編寫的攝像頭捕獲程序,能夠將攝像頭捕獲的畫面顯示在界面上。

代碼片段和文件信息
/************************************************************************
*?Copyright(c)?2011??謝小軍
*?Brief:?視頻捕捉Qt+OpenCV
*?Version:?1.0
*?Author:?謝小軍
*?Email:?346944475@qq.com
*?Date: 2011/12/05
************************************************************************/
#include?“camcapture.h“
camCapture::camCapture(QWidget?*parent?Qt::WFlags?flags)
:?QMainWindow(parent?flags)
{
count=0;
//?初始化處理,建立QImage和frame的關聯(lián),開啟定時器
//打開攝像頭端口
//方法1
/*
CvCapture*?pCapture?=?NULL;
if(?!(pCapture?=?cvCaptureFromCAM(-1)))
{
fprintf(stderr?“Can?not?open?camera.\n“);
return?-2;
}*/
path=QCoreApplication::applicationDirPath();//獲得當前路徑
//方法2
capture.open(-1);//打開攝像頭端口
if?(capture.isOpened())//判斷是否打開
{
capture?>>?frame;//往矩陣里存數(shù)據(jù)流
if?(!frame.empty())//判斷是否取出流
{
cv::cvtColor(frame?frame?CV_BGR2RGB);//色彩空間轉換?
/*函數(shù)?cvCvtColor?將輸入圖像從一個色彩空間轉換為另外一個色彩空間。函數(shù)忽略?IplImage?頭中定義的 colorModel?和?channelSeq?域,所以輸入圖像的色彩空間應該正確指定?(包括通道的順序,對RGB空間而言, BGR 意味著布局為?B0?G0?R0?B1?G1?R1?...?層疊的?24-位格式,而?RGB?意味著布局為?R0?G0?B0?R1?G1?B1?. ..?層疊的24-位格式.?
*/
cv::flip(frame?frame?1);//垂直,水平或即垂直又水平翻轉二維數(shù)組
image?=?new?QImage((const?unsigned?char*)(frame.data)?frame.cols?frame.rows?QImage::Format_RGB888);//將矩陣轉換成Qimage類型
timer?=?new?QTimer(this);//設置時間值:QTimer類提供了定時器信號和單觸發(fā)定時器
timer->setInterval(30);//設置信號槽觸發(fā)間隔
connect(timer?SIGNAL(timeout())?this?SLOT(nextframe()));//信號槽連接
//connect(ui.pushButtonSIGNAL(clicked())thisSLOT(SavePicture()));
timer->start();//開始一個msec毫秒定時的定時器。
}
}
ui.setupUi(this);//更新用戶接口,細微變化
}
camCapture::~camCapture()
{
delete?image;//析構
delete?timer;//析構
}
void?camCapture::paintEvent(QPaintEvent?*?e)
{
//?更新圖像
QPainter?painter(this);//繪制,在窗口部件上
painter.drawImage(QPoint(35?100)?*image);//在點p繪制圖像i。int?conversion_flags?=?0使用conversion_flags來指定你希望發(fā)生什么。?
//QPoint(20?30):點的坐標
}
void?camCapture::nextframe()//槽函數(shù)
{
//?更新數(shù)據(jù)
capture?>>?frame;//將從攝像頭獲取的流讀入到矩形框里
if?(!frame.empty())//判斷矩形框類容不為空
{
cv::cvtColor(frame?frame?CV_BGR2RGB);//顏色轉換
cv::flip(frame?frame?1);//垂直,水平或即垂直又水平翻轉二維數(shù)組
this->update();//更新數(shù)據(jù)
}
count++;
if?(count==30)
SavePicture();
}
//yearmonthhourdayminutesecond;
void?camCapture::SavePicture()//保存圖片
{
//獲得時間
year=myDate.currentDate().year();
month=myDate.currentDate().month();
day=myDate.currentDate().day();
hour=myTime.currentTime().hour();
minute=myTime.currentTime().minute();
second=myTime.currentTime().second();
mm=myTime.currentTime().msec();
char?*?addr=new?char[300];
sprintf(addr“./pecture/%d-%d-%d?%d-%d-%d?%d.jpg“(const?char*)?path.toLocal8Bit()yearmonthdayhourminutesecondmm);
image->save(addr);
delete?addr;
count=0;
/*
FILE?*fp;
if?(!(fp=fopen(addr“w“)))
{
delete?addr;
count=0;
return;
}
fclose(fp);
QFile?m_infile(addr);
if?(m_infile.open(QIODevice::WriteOnly))
{
QDataStream?out(&m_infile);
out.setVersion(QDataS
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????3511??2011-12-21?19:23??Qt+OpenCV讀取攝像頭\camCapture\camcapture.cpp
?????文件???????3419??2011-12-07?10:03??Qt+OpenCV讀取攝像頭\camCapture\camcapture.cpp.bak
?????文件???????1318??2011-12-20?21:14??Qt+OpenCV讀取攝像頭\camCapture\camcapture.h
?????文件?????????70??2011-12-05?14:31??Qt+OpenCV讀取攝像頭\camCapture\camcapture.qrc
????..A..H.?????16896??2011-12-06?19:19??Qt+OpenCV讀取攝像頭\camCapture\camCapture.suo
?????文件??????62706??2011-12-07?08:35??Qt+OpenCV讀取攝像頭\camCapture\camcapture.ui
?????文件???????8634??2011-12-06?15:18??Qt+OpenCV讀取攝像頭\camCapture\camCapture.vcproj
?????文件???????1429??2011-12-05?16:24??Qt+OpenCV讀取攝像頭\camCapture\camCapture.vcproj.HP98402794308.Administrator.user
?????文件???????1421??2011-12-22?08:47??Qt+OpenCV讀取攝像頭\camCapture\camCapture.vcproj.lenovo-PC.lenovo.user
?????文件????????494??2011-12-06?16:27??Qt+OpenCV讀取攝像頭\camCapture\camCapture.vcproj.vspscc
?????文件???????7410??2011-12-21?20:01??Qt+OpenCV讀取攝像頭\camCapture\Debug\BuildLog.htm
?????文件????????621??2011-12-21?20:01??Qt+OpenCV讀取攝像頭\camCapture\Debug\camCapture.exe.intermediate.manifest
?????文件?????437956??2011-12-21?19:23??Qt+OpenCV讀取攝像頭\camCapture\Debug\camcapture.obj
?????文件?????161566??2011-12-21?20:01??Qt+OpenCV讀取攝像頭\camCapture\Debug\main.obj
?????文件?????163322??2011-12-21?19:23??Qt+OpenCV讀取攝像頭\camCapture\Debug\moc_camcapture.obj
?????文件?????????65??2011-12-21?20:01??Qt+OpenCV讀取攝像頭\camCapture\Debug\mt.dep
?????文件????2264064??2011-12-21?20:01??Qt+OpenCV讀取攝像頭\camCapture\Debug\vc90.idb
?????文件????2060288??2011-12-21?20:01??Qt+OpenCV讀取攝像頭\camCapture\Debug\vc90.pdb
?????文件???????2410??2011-12-21?19:23??Qt+OpenCV讀取攝像頭\camCapture\GeneratedFiles\Debug\moc_camcapture.cpp
?????文件??????43824??2011-12-07?08:35??Qt+OpenCV讀取攝像頭\camCapture\GeneratedFiles\ui_camcapture.h
?????文件????????213??2011-12-21?20:00??Qt+OpenCV讀取攝像頭\camCapture\main.cpp
?????文件????????971??2011-12-05?14:31??Qt+OpenCV讀取攝像頭\camCapture.sln
????..A..H.?????16384??2011-12-22?08:47??Qt+OpenCV讀取攝像頭\camCapture.suo
?????文件?????133120??2011-12-21?20:01??Qt+OpenCV讀取攝像頭\Debug\camCapture.exe
?????文件????1402880??2011-12-21?20:01??Qt+OpenCV讀取攝像頭\Debug\camCapture.ilk
?????文件????2706432??2011-12-21?20:01??Qt+OpenCV讀取攝像頭\Debug\camCapture.pdb
?????文件????2086912??2011-10-26?23:19??Qt+OpenCV讀取攝像頭\Debug\cv210.dll
?????文件????2201600??2011-10-26?23:16??Qt+OpenCV讀取攝像頭\Debug\cxcore210.dll
?????文件?????781312??2011-10-26?23:20??Qt+OpenCV讀取攝像頭\Debug\highgui210.dll
?????文件??????26624??2011-08-23?23:08??Qt+OpenCV讀取攝像頭\Debug\imageformats\qgif4.dll
............此處省略92個文件信息
評論
共有 條評論