日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

opencv方框内图像保存_opencv::将两幅图像合并后,在同一个窗口显示;并将合并的图像流保存成视频文件...

發布時間:2025/3/12 编程问答 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 opencv方框内图像保存_opencv::将两幅图像合并后,在同一个窗口显示;并将合并的图像流保存成视频文件... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

/**

* @file main-opencv.cpp

* @date July 2014

* @brief An exemplative main file for the use of ViBe and OpenCV*/

//#include

#include "vibe-background-sequential.h"

using namespacecv;using namespacestd;const int minArea = 2; //舍去面積極小的方框

const double maxAreaRatio = 0.1; //舍去面積極大的方框

const double boxRatio = 0.1; //舍去長寬比嚴重失衡的方框

/**

* Displays instructions on how to use this program.*/

voidhelp()

{

cout<< "--------------------------------------------------------------------------" <" <

}void processVideo(char*videoFilename);void contour(const Mat &mor, Mat &img);/**

* Main program. It shows how to use the grayscale version (C1R) and the RGB version (C3R).*/

int main(int argc, char*argv[])

{/*Print help information.*/help();/*Check for the input parameter correctness.*/

/*if (argc != 2) {

cerr <

cerr <

return EXIT_FAILURE;

}

/* Create GUI windows.*/

//namedWindow("Frame");//namedWindow("Segmentation by ViBe");

processVideo("framelink_yd.avi"); //讀取 framelink_yd.avi 視頻進行處理

/*Destroy GUI windows.*/destroyAllWindows();returnEXIT_SUCCESS;

}/**

* Processes the video. The code of ViBe is included here.

*

* @param videoFilename The name of the input video file.*/

void processVideo(char*videoFilename)

{

VideoCapture capture(videoFilename);/*Create the capture object.*/

if (!capture.isOpened()) {

cerr<< "Unable to open video file:" << videoFilename<< endl; /*Error in opening the video input.*/exit(EXIT_FAILURE);

}

clock_t start, finish;doubletotal;

start=clock();/*Variables.*/

static int frameNumber = 1; /*The current frame number*/

int lastCount = 0;int probFactor = gradient_Factor; /*概率因子,用梯度因子初始化概率因子*/Mat frame,frame1;/*Current frame.*/Mat segmentationMap;/*Will contain the segmentation map. This is the binary output map.*/

int keyboard = 0; /*Input from keyboard. Used to stop the program. Enter 'q' to quit.*/

char fileName[200] = { 0};int sampleCounts[10] = {0};int speSamples[10] = {0};

vibeModel_Sequential_t*model = NULL; /*Model used by ViBe.*/

int heig = 512;int widt = 1340;

Mat res= Mat::zeros(heig, widt, CV_8UC3); //res為三通道像素幀,用來保存最后合并的圖像

/*創建保存視頻的文件名并打開*/

const string Name = "res.avi";

VideoWriter writer;

Size sz(widt, heig);

writer.open(Name, CV_FOURCC('M', 'J', 'P', 'G'), 70, sz, true);while ((char)keyboard != 'q' && (char)keyboard != 27 ) { /*Read input data. ESC or 'q' for quitting.*/

if (!capture.read(frame1)) { /*Read the current frame.*/cerr<< "Unable to read next frame." <

cerr<< "Exiting..." <

}/*Applying ViBe.

* If you want to use the grayscale version of ViBe (which is much faster!):

* (1) remplace C3R by C1R in this file.

* (2) uncomment the next line (cvtColor).*/cvtColor(frame1, frame, CV_BGR2GRAY);//將三通道圖像幀轉換為單通道

if ( frameNumber==1) {

segmentationMap=Mat(frame.rows, frame.cols, CV_8UC1);

model= (vibeModel_Sequential_t*)libvibeModel_Sequential_New();

libvibeModel_Sequential_AllocInit_8u_C1R(model, frame.data, frame.cols, frame.rows);

class_samples(model,frame.data, sampleCounts,speSamples,frame.cols, frame.rows);

}

/*ViBe: Segmentation and updating.*/libvibeModel_Sequential_Segmentation_8u_C1R(model, frame.data, segmentationMap.data);

libvibeModel_Sequential_Update_8u_C1R(model, frame.data, segmentationMap.data,&probFactor,frameNumber);

medianBlur(segmentationMap, segmentationMap,3); /*3x3 median filtering*/contour(segmentationMap, frame1); //在原圖上框出動目標,至此圖像處理完畢//sprintf(fileName, "results55_2/%06d.jpg",frameNumber);//imwrite(fileName, frame1);

Mat segmentationMap1;//新定義一個幀變量,不能 cvtColor(segmentationMap, segmentationMap, CV_GRAY2BGR),因為 segmentationMap 為單通道幀;

cvtColor(segmentationMap, segmentationMap1, CV_GRAY2BGR); //將單通道幀圖像 segmentationMap 轉化為三通道segmentationMap1,因為 res 幀為三通道幀圖像//segmentationMap1要合并在 res 中;

/*Shows the current frame and the segmentation map.*/

//imshow("Frame", frame1);//imshow("Segmentation by ViBe", segmentationMap);

/*將 segmentationMap1 和 frame1 合并成一幀存放在 res 中*/segmentationMap1.copyTo(res(Rect(0, 0, 640, 512)));

frame1.copyTo(res(Rect(700, 0, 640, 512)));

imshow("res", res); //顯示合并后的圖像/*將 res 寫入打開的視頻文件中*/writer<

keyboard= waitKey(1); /*Gets the input from the keyboard.*/}

finish=clock();

total=(double)(finish-start);

cout<

cout<

capture.release();/*Delete capture object.*/libvibeModel_Sequential_Free(model);/*Frees the model.*/}/*框出運動目標*/

void contour(const Mat &mor, Mat &img)

{int img_size = img.cols *img.rows;

Mat tmp= (mor == 255);//Each detected contour is stored as a vector of points

vector >contours;

vector hierarchy; //containing information about the image topology

findContours(tmp, contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);for (size_t k = 0; k < contours.size(); k++) {

Rect rect=boundingRect(contours[k]);double whratio = double(rect.width) / double(rect.height);double hwratio = double(rect.height) / double(rect.width);double ratio =min(hwratio, whratio);double area =rect.area();//框出符合條件的輪廓,舍去: 面積很小的, 面積很大的, 長寬比嚴重失調的

if (area > minArea && area < img_size*maxAreaRatio && ratio >boxRatio) {int w =rect.width;int h =rect.height;if(rect.width < 20)

rect.width= 20;/*if(rect.width < 6)

rect.width = 2*rect.width;

else

rect.width = rect.width + rect.width/2;*/

if(rect.height < 20)

rect.height= 20;/*if(rect.height < 6)

rect.height = 2*rect.height;

else

rect.height = rect.height + rect.height/2;*/

int w_add = (rect.width - w)/2;int h_add = (rect.height - h)/2;

rect.x= rect.x -h_add;

rect.y= rect.y -w_add;

rectangle(img, rect, Scalar(0,0,255));

}

}

}

總結

以上是生活随笔為你收集整理的opencv方框内图像保存_opencv::将两幅图像合并后,在同一个窗口显示;并将合并的图像流保存成视频文件...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 一区二区三区波多野结衣 | 国产精品久久一区 | 蜜臀一区二区三区 | 国产av无码专区亚洲精品 | 在哪里可以看毛片 | 欧美特级aaa | 午夜成年视频 | 99久久精品国产一区二区三区 | 成人黄色视屏 | 一区二区三区四区在线播放 | 伊人一二三 | 欧美3p在线观看 | 国产午夜精品福利视频 | 超碰在线cao| 草莓视频18免费观看 | 成人羞羞网站 | 最近中文字幕一区二区 | 超碰日日干 | 涩涩视屏| 中文字字幕在线中文乱码电影 | 成人夜色 | 国产一级高清视频 | 欧美成人另类 | 白嫩情侣偷拍呻吟刺激 | 色乱码一区二区三区熟女 | www.奇米| 交视频在线播放 | 美女爽爽爽 | 一区二区一级片 | 国产中文一区二区三区 | www.av72| 久久伊人一区二区 | 亚洲一二区 | 精品无人国产偷自产在线 | 蜜桃久久av一区 | 亚洲网站在线免费观看 | 91porny丨首页入口在线 | 性视频黄色 | 国产在线免费 | 日韩性网 | 久久久精品一区二区三区 | 亚洲欧洲日本一区二区三区 | 男女调教视频 | 国产伦精品一区 | 就去色av | 台湾佬中文在线 | 好妞色妞国产在线视频 | 精品蜜桃av| 成人免费视频a | 一区二区三区久久 | 日韩中文在线观看 | 特大黑人巨交性xxxx | 天天舔天天 | 中文字幕亚洲乱码熟女一区二区 | 国内一级黄色片 | 亚洲一区无 | 国产波霸爆乳一区二区 | a天堂v| 久久99精品久久久久婷婷 | 亚洲18在线看污www麻豆 | 亚洲国产经典 | 天天天天天天天干 | 欧美日韩一级片在线观看 | 中文字幕高清视频 | 91在现看| 亚洲av成人精品一区二区三区在线播放 | 久久91亚洲 | 娇妻被老王脔到高潮失禁视频 | 红桃视频一区二区三区免费 | 日本一级淫片色费放 | 久久久久久久久福利 | 黄色一级片黄色一级片 | 久久99久久久 | 亚洲av色香蕉一区二区三区 | 少妇一级淫免费放 | 国产在线精品一区二区三区 | 国产电影一区二区三区爱妃记 | 国产毛片一区二区三区va在线 | 手机看片欧美 | 国产精品男同 | 欧美一二三区视频 | 亚洲做受高潮无遮挡 | 青青视频网站 | 97超碰人人看| 手机看片国产1024 | 专业操老外| 国产精品9191 | 国产精品久久中文字幕 | h在线网站| 日韩精品国产精品 | 国产精品一二三区在线观看 | 国产肉体xxxx裸体784大胆 | 亚洲精品一线 | 激情国产一区 | 国产亚洲欧美一区二区 | av在线播放网址 | 欧美麻豆视频 | 欧美成人激情 | 久久第一页 |