OpenCV常用操作之計時縮放旋轉(zhuǎn)鏡像_第1頁
OpenCV常用操作之計時縮放旋轉(zhuǎn)鏡像_第2頁
OpenCV常用操作之計時縮放旋轉(zhuǎn)鏡像_第3頁
OpenCV常用操作之計時縮放旋轉(zhuǎn)鏡像_第4頁
OpenCV常用操作之計時縮放旋轉(zhuǎn)鏡像_第5頁
已閱讀5頁,還剩3頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

1、常用操作在OpenCVf發(fā)過程中用于測試性能計時的:計時(計算處理的時間)。在一般的圖像處理中有的幾個操作:縮放(放大、縮小),旋轉(zhuǎn)(90度的倍數(shù))、鏡像(x軸反向、y軸反向)。注意:意角度的旋轉(zhuǎn)使用cv:Mat不太合適,開發(fā)過程中會用到其他 ui框架, 所以使用其他ui框架做旋轉(zhuǎn)是比較合適的。計時函數(shù)OpenCV!供了兩個漸變的計時函數(shù):getTickCount()和 getTickFrequency()。getTickCount() : getTickCount()函數(shù)返回CPU自某個事件(如啟動電腦)以 來走過的時鐘周期數(shù)。getTickFrequency() : getTickFreq

2、uency()函數(shù)返回 CPUK秒鐘所走的時鐘周 期數(shù)。測試結(jié)果如下:now t -i me a J ©=£= = =? = = = = = =t CVJ (cetTickCountO »cw: :swtTickCtjunt(> = 235622S74347cw::S*tTickCount(> - 235622577224cwi:getTickF rsquency() = 10OQG9Q0 , ms: 0 = tost cvitgetTickCount(), cw::getTickCountC) = 255622S7625S cv::s«tT

3、ickCount() = 235624583319cw :: get 11 cl< Frequency ( ) = 10000900 t aim: ?Q0 = = = = = = = = = = = = = = = = teat cv11 gttTiekCount(), CVt:gQtTickCount(> - 2J562458e349 cv: :a«iTickCtjunt() = 235626S90&12 cv* :getTic*<Frequtncy () = 10900900 T «ns: 4。 = testiekCount(),cv:: go

4、cTickCountO = 23562£597<»19 cv:getT i ckCountf2S56 346Q1530 v : : gstTi ckFrsqoitrtcy ( ) - 1G000000 , mi t 600 = = = cv s:setTickCount(), cv:gerT1ckCount() - 235636075©5 CVt:gQtTickCountf - 2J564361t455c w : : stT i c k F t Qu«nc y ( ) - 1G0G00Q0 , ni : = tfst cv1:getTickCoun

5、t()r Cwi ipetTlckCountO = 235642622727 cv:: gQtTickCountO - 235652630821ew i : etT i ckF rquvncy ()=工。由必T i 1000 =二=二二二二二二二二= = = = =cv : : Ee-tTickCount (),cv* : getTickCount( = 23&6=>26570Se cv::£erT1ckCounc() = 235664661186C v : : g.vtT i c. kF r Qqutr>Cy ) 160600 , 1ii拿; IN®由

6、 = test cv:etTirkCoun()> cv: ietT-iekCountO = 25664668201 <vi : cetTiCkCOuntO 營 23S67afe?feJ85 tv:i c k F i Qut»nc y () = 100®G9®0 ,; L40G= 七2七 亡n:tgtT3ukCQun七(), evi:eetTickCountC) = 2356787Q&93 evileetTickGountf3 = 235694T1239fe cv:a«tl ickFr() - 1$0QG000 , ni t L60Gn

7、ow t i me11 1now r i me a t 2now 11 (ne s : 3now 11ew $: 6no*v t i rne s : 7now t i ititf m t &cv:getTickFrequency()獲取的頻率為10,000,000,得到cpu的周期為一千萬次每秒。訪問圖像中像素的三類方法cv:Mat訪問的三類方法:方法一:at函數(shù)方法二:使用迭代器方法三:通過數(shù)據(jù)指針旋轉(zhuǎn)(90度的整數(shù)倍)旋轉(zhuǎn)90°的整數(shù)就是對矩陣位置進行變換,如下圖:喉時仲90度及時鐘佻1度餐時鐘如度旋轉(zhuǎn)函數(shù) 1: cv:transpose()該函數(shù)無任何函數(shù),直接對矩陣進

8、行順時鐘旋轉(zhuǎn)90° ,函數(shù)原型如下:CV_EXPORTS_W void transpose(InputArray src, OutputArray dst);旋轉(zhuǎn)函數(shù) 2: cv:rotate()該函數(shù)旋轉(zhuǎn)函數(shù),三個枚舉可以旋轉(zhuǎn) 90° , 180° , 270。,逆時針旋轉(zhuǎn)900就是順時鐘270° ,函數(shù)原型如下:CV_EXPORTS_W void rotate(InputArray src, OutputArray dst, int rotateCode);參數(shù)一:輸入mat參數(shù)二:輸出mat參數(shù)三:旋轉(zhuǎn)枚舉,如下:enum RotateFlags

9、ROTATE_90_CLOCKWISE = 0, /Rotate 90 degrees clockwiseROTATE_180 = 1,/Rotate 180 degrees clockwiseROTATE_90_COUNTERCLOCKWISE = 2, /Rotate 270 degrees clockwise;代碼示例:cv:rotate(srcMat, srcMat, cv:ROTATE_90_CLOCKWISE);鏡像(x軸翻轉(zhuǎn),y軸翻轉(zhuǎn))鏡像就是對X軸和Y軸的值翻轉(zhuǎn)對調(diào),如下圖:1234 56軸翻轉(zhuǎn)4 56123 |翻轉(zhuǎn)函數(shù):cv:flip該函數(shù)為翻轉(zhuǎn)函數(shù),函數(shù)圓形如下:CV_EX

10、PORTS_W void flip(InputArray src, OutputArray dst, int flipCode);參數(shù)一:輸入mat參數(shù)二:輸出mat參數(shù)三:只有3種值,小于0,等于0,大于0,分別對應(yīng)xy軸翻轉(zhuǎn)、x軸翻轉(zhuǎn)、 y軸翻轉(zhuǎn)。代碼示例:cv二flip(srcMat, srcMat, 0);縮放 縮放函數(shù):cv二resize該函數(shù)為縮放函數(shù),特別注意:函數(shù)縮放會失真,尤其是以縮放后的圖像繼續(xù) 縮放會原來大小,所以筆者建議,縮放用緩存,緩存存放原圖,每次以原圖縮 放。該函數(shù)原形如下:CV_EXPORTS_W void resize( InputArray src, Out

11、putArray dst,Size dsize, double fx = 0, double fy = 0, int interpolation = INTER_LINEAR );參數(shù)一:輸入mat參數(shù)二:輸出mat參數(shù)三:縮放后的大小參數(shù)四:x 縮放比例,一般默認0 就可以參數(shù)五:y 縮放比例,一般默認0 就可以參數(shù)六:差值,一般默認即可此處額外介紹下差值的枚舉:= 0,/ 最臨近差值= 1, / 雙線性差值= 2, / 雙立方差值= 3,enum InterpolationFlagsINTER_NEARESTINTER_LINEARINTER_CUBICINTER_AREAINTER_LA

12、NCZOS4 = 4, / 附近像素及原像素加權(quán)取值INTER_LINEAR_EXACT = 5,INTER_MAX = 7,WARP_FILL_OUTLIERS = 8,WARP_INVERSE_MAP = 16;DemOK 碼void OpenCVManager:testCommonOperate()#define TEST_GET_TICK_COUNT (1)#define TEST_ROTATE_90 (1)#if TEST_GET_TICK_COUNT / 測試計時函數(shù)for(int index = 0; index < 10; index+)int64 tickCount =

13、 cv:getTickCount();qDebug() << _FUNCTION_ << _LINE_ << "= test cv:getTickCount(), now times:" << index;qDebug() << _FUNCTION_ << _LINE_ << "cv:getTickCount() =" << tickCount;/ Qt 的線程睡眠函數(shù)QThread:msleep(200 * index);int64 tickCount2 =

14、 cv:getTickCount();qDebug() << _FUNCTION_ << _LINE_ << "cv:getTickCount() =" << tickCount2;int64 ms = (double)tickCount2 - tickCount) * 1000.0f/ cv:getTickFrequency();qDebug() << _FUNCTION_ << _LINE_ << "cv:getTickFrequency() =" <<

15、(int64)cv:getTickFrequency() << ", ms:" << ms;#endif#if TEST_ROTATE_90cv:Mat srcMat;QString fileName ="D:/qtProject/openCVDemo/openCVDemo/modules/openCVManager/images/1.jpg"srcMat = cv:imread(fileName.toStdString();if(!srcMat.data)qDebug() << _FILE_ << _LI

16、NE_ << "Failed to load image:" << fileName;return;cv:imshow("OpenCVDemo v1.5.0 QQ:21497936 blog: srcMat);float scaleStep = 0.05f;while(true)int key = cv:waitKey();/ 逆時鐘旋轉(zhuǎn)90 度if(key = '1')int64 tickCount = cv:getTickCount();qDebug() << _FUNCTION_ << _LIN

17、E_ << "cv:getTickCount() =" << tickCount;cv:rotate(srcMat, srcMat, cv:ROTATE_90_COUNTERCLOCKWISE);int64 tickCount2 = cv:getTickCount();qDebug() << _FUNCTION_ << _LINE_ << "cv:getTickCount() =" << tickCount2;int64 ms = (double)tickCount2 - tickC

18、ount) * 1000.0f/ cv:getTickFrequency();qDebug() << _FUNCTION_ << _LINE_ << "take time ms:" << ms;cv:imshow("OpenCVDemo v1.5.0 QQ:21497936 blog: srcMat);else if(key = '2') / 順時鐘旋轉(zhuǎn)90 度int64 tickCount = cv:getTickCount();qDebug() << _FUNCTION_ <&l

19、t; _LINE_ << "cv:getTickCount() =" << tickCount;cv:rotate(srcMat, srcMat, cv:ROTATE_90_CLOCKWISE);int64 tickCount2 = cv:getTickCount();qDebug() << _FUNCTION_ << _LINE_ << "cv:getTickCount() =" << tickCount2;int64 ms = (double)tickCount2 - tickC

20、ount) * 1000.0f/ cv:getTickFrequency();qDebug() << _FUNCTION_ << _LINE_ << "take time ms:" << ms;cv:imshow("OpenCVDemo v1.5.0 QQ:21497936 blog: srcMat);else if(key = '3') / x 軸翻轉(zhuǎn)(鏡像)int64 tickCount = cv:getTickCount();qDebug() << _FUNCTION_ <&l

21、t; _LINE_ << "cv:getTickCount() =" << tickCount;cv:flip(srcMat, srcMat, 0);int64 tickCount2 = cv:getTickCount();qDebug() << _FUNCTION_ << _LINE_ << "cv:getTickCount() =" << tickCount2;int64 ms = (double)tickCount2 - tickCount) * 1000.0f/ cv:get

22、TickFrequency();qDebug() << _FUNCTION_ << _LINE_ << "take time ms:" << ms;cv:imshow("OpenCVDemo v1.5.0 QQ:21497936 blog: srcMat);else if(key = '4') / y 軸翻轉(zhuǎn)(鏡像)int64 tickCount = cv:getTickCount();qDebug() << _FUNCTION_ << _LINE_ << &quo

23、t;cv:getTickCount() =" << tickCount;cv:flip(srcMat, srcMat, 1);int64 tickCount2 = cv:getTickCount();qDebug() << _FUNCTION_ << _LINE_ << "cv:getTickCount() =" << tickCount2;int64 ms = (double)tickCount2 - tickCount) * 1000.0f/ cv:getTickFrequency();qDebug(

24、) << _FUNCTION_ << _LINE_ << "take time ms:" << ms;cv:imshow("OpenCVDemo v1.5.0 QQ:21497936 blog: srcMat);else if(key = '5') / 縮小int64 tickCount = cv:getTickCount();qDebug() << _FUNCTION_ << _LINE_ << "cv:getTickCount() =" &l

25、t;< tickCount;cv:resize(srcMat, srcMat, cv:Size(int)(srcMat.cols * (1.0f - scaleStep),(int)(srcMat.rows * (1.0f - scaleStep);int64 tickCount2 = cv:getTickCount();qDebug() << _FUNCTION_ << _LINE_ << "cv:getTickCount() =" << tickCount2;int64 ms = (double)tickCount2 - tickCount) * 1000.0f/ cv:getTickFrequ

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論