OPENCV學習第九章第一題

來源:互聯網
上載者:User
// 9-1.cpp : 定義控制台應用程式的進入點。///*===========================================================================名稱:9-1時間:2013.07.04說明:============================================================================*/#include "stdafx.h"#include "cv.h"#include "highgui.h"#include "cxcore.h"int _tmain(int argc, _TCHAR* argv[]){//聲明三個映像指標,分別指向載入的映像、轉化為單通道映像、處理好映像IplImage* pFrame = NULL;      IplImage* pFrImg = NULL;     IplImage* pBkImg = NULL;  //聲明三個矩陣變換指標    CvMat* pFrameMat = NULL;      CvMat* pFrMat = NULL;     CvMat* pBkMat = NULL;     int nFrmNum = 0;//建立三個顯示映像的視窗cvNamedWindow("video", 1); cvNamedWindow("background",1);     cvNamedWindow("foreground",1); //設定顯示視窗的位置座標    cvMoveWindow("video", 30, 0);     cvMoveWindow("background", 360, 0);     cvMoveWindow("foreground", 690, 0); //為pFrame載入本地映像,並初始化映像指標pBkImg、pFrImgpFrame = cvLoadImage("D://12.jpg");pBkImg = cvCreateImage(cvGetSize(pFrame), IPL_DEPTH_8U, 1);pFrImg = cvCreateImage(cvGetSize(pFrame), IPL_DEPTH_8U, 1);//初始化三個矩陣變換函數pBkMat、pFrMat、pFrameMatpBkMat = cvCreateMat(pFrame->height, pFrame->width, CV_32FC1);pFrMat = cvCreateMat(pFrame->height, pFrame->width, CV_32FC1);pFrameMat = cvCreateMat(pFrame->height, pFrame->width, CV_32FC1);//色彩空間轉化,變為灰階映像cvCvtColor(pFrame, pBkImg, CV_BGR2GRAY);cvCvtColor(pFrame, pFrImg, CV_BGR2GRAY); //把載入的映像轉化為矩陣cvConvert(pFrImg, pFrameMat);cvConvert(pFrImg, pFrMat); cvConvert(pFrImg, pBkMat); //高斯濾波cvSmooth(pFrameMat, pFrameMat, CV_GAUSSIAN, 3, 0, 0,0); //函數cvAbsDiff計算兩個數組差的絕對值cvAbsDiff(pFrameMat, pBkMat, pFrMat);//映像二值化cvThreshold(pFrMat, pFrImg, 20, 255, CV_THRESH_BINARY); //用來更新移動平均cvRunningAvg(pFrameMat, pBkMat, 0.003, NULL); //把矩陣轉化為映像cvConvert(pBkMat, pBkImg);//映像顯示cvShowImage("video", pFrame);     cvShowImage("background", pBkImg);     cvShowImage("foreground", pFrImg);     cvWaitKey(0);//關閉所有視窗    cvDestroyAllWindows();     //釋放映像記憶體與矩陣cvReleaseImage(&pFrImg);     cvReleaseImage(&pBkImg); cvReleaseMat(&pFrameMat);     cvReleaseMat(&pFrMat);     cvReleaseMat(&pBkMat);return 0;}

1.聲明三個映像指標與三個矩陣

2.初始化三個映像指標與三個矩陣

3.色彩空間的轉換

4.把初始化的映像指標轉化為矩陣指標

5.高斯濾波

6.求兩個矩陣之差輸出

7.輸出映像的二值化

8.更新移動平均

9.把矩陣轉化為映像指標

 

10.映像顯示

聯繫我們

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