opencv2中,提供了两个视频操作相干的类,VideoCapture和VideoWriter,固然也有相对应的构造函数。
对VideoCapture,其有以下几个操作函数:
open(const string &filename) //打开视频文件
open(int device) //打开摄像头,device为装备序号
isOpened() //判断视频文件或摄像头是不是打开,其返回值为bool型
release() //关闭视频文件或摄像头
grab() //获得视频或摄像头下1帧,若获得成功,则返回TRUE,其函数类型也是bool型。
retrieve(Mat& image , int channel=()) //解码刚刚获得到的1帧图象,并将其赋给image,这个函数的返回值也是bool型。
read(Mat& image) //获得、解码和读取视频的下1帧。在opencv中,其用“>>”操作符重载了这个函数,即 video >> image
get(int propId) //返回视频的属性
propId取值不同,则返回的属性也不同。当propId取以下值时:
CV_CAP_PROP_POS_MSEC 以毫秒或时间戳的情势当前视频文件的位置
CV_CAP_PROP_POS_FRAMES 以0开始的视频帧解码捕获索引
CV_CAP_PROP_POS_AVI_RATIO 视频的相对位置,0为开始,1为结束
CV_CAP_PROP_FRAME_WIDTH 视频帧图片的宽度
CV_CAP_PROP_FRAME_HEIGHT 视频帧图片的高度
CV_CAP_PROP_FPS 帧率
CV_CAP_PROP_FOURCC 视频的4字符代码
CV_CAP_PROP_FRAME_COUNT 视频的总帧数
CV_CAP_PROP_FORMAT 视频的图片格式
CV_CAP_PROP_MODE 后端特定值唆使当前捕获模式
下面几个属性只在摄像模式下有效:
CV_CAP_PROP_BRIGHTNESS 图象的亮度
CV_CAP_PROP_CONTRAST 图象对照度
CV_CAP_PROP_SATURATION 图象的饱和度
CV_CAP_PROP_HUE 图象的色度
CV_CAP_PROP_EXPOSURE 图象的暴光
CV_CAP_PROP_CONVERT_RGB图象是不是转换为RGB型
set(int propId) //设置属性,其参数的取值和get函数的取值1样
对VideoWriter,其有以下几个操作函数:
open(const string &filename, int fourcc, double fps, Size frameSize, color = true)
以上几个参数在上文中均已介绍过了。
isOpened() //与前面的是1个意思
write(const Mat& image) //opencv中也一样重载了这个函数,即用操作符<<
下面看段程序,程序的功能是将1个段视频变小,即原来1024*780的视频,变成320*280,为了多使用几个视频操作函数,所以有些地方可以大大简化或修改的我没有修改,为了展现1下各个函数的用法。
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <opencv2/opencv.hpp>
#include <iostream>
#include <stdio.h>
using namespace std;
using namespace cv;
int main(int argc, const char** argv)
{
Mat frame;
VideoCapture video;
VideoWriter newVideo;
double fourcc, fps, width, height;
video.open("25.avi"); //打开视频
fourcc = video.get(CV_CAP_PROP_FOURCC);
fps = video.get(CV_CAP_PROP_FPS);
width = video.get(CV_CAP_PROP_FRAME_WIDTH);
height = video.get(CV_CAP_PROP_FRAME_HEIGHT); //得到视频的1些参数
//新建1个新的视频
markVideo.open("markVideo10.avi", fourcc, fps);
if (video.isOpened() && markVideo.isOpened() )
{
while(true){
video >> frame; //读取视频的每个帧
resize(frame, frame, Size(320, 280)); //将视频的每帧都缩小
if (!frame.empty()){
markVideo << frame; //将缩小后的每个帧都写进新的视频
}
else{printf(" –(!) No captured frame — Break!"); break;}
if ((char)waitKey(1) == 'c') {
video.release(); markVideo.release();
break;
}
}
}
return 0;
}
波比源码 » 【opencv2】对视频的操作
levaquin price order levofloxacin 250mg pills
purchase avodart for sale buy ondansetron pills order ondansetron 4mg online
oral ampicillin 250mg bactrim 960mg pills buy generic erythromycin 250mg
sildenafil 50mg sale buy methocarbamol generic purchase robaxin online cheap
suhagra 100mg tablet cheap sildenafil 100mg estrace 1mg pills
lamotrigine 200mg over the counter tretinoin cream tablet retin cream over the counter
tadalafil generique en pharmacie pharmacie en ligne viagra 50mg generique sildenafil
tadalafil 10mg kaufen cialis 5mg kaufen ohne rezept sildenafil fГјr frauen
cheap doxycycline order clomiphene 50mg generic buy lasix 40mg online cheap
altace 5mg usa order avapro 150mg buy astelin 10ml online cheap
buy catapres without prescription generic minocycline 50mg buy tiotropium bromide 9mcg
order molnupiravir sale cefdinir 300mg pill buy prevacid without prescription
imuran 100mcg for sale buy imuran 100 mcg sildenafil 100mg pills for sale
purchase cialis without prescription purchase pyridium pills cheap amantadine 100 mg
revia 50mg us buy generic femara order abilify 30mg pills
provera 5mg us order periactin 4mg cyproheptadine cost
order fluvoxamine 100mg pills luvox 50mg drug buy glipizide
buy generic nootropil 800mg real viagra pharmacy prescription sildenafil in usa
buy chloroquine 250mg online order chloroquine 250mg generic order generic olumiant 4mg
brand glucophage 500mg tadalafil 10mg pills buy tadalafil 20mg pill
norvasc over the counter purchase norvasc for sale order tadalafil 10mg sale
buy viagra 50mg sale cheapest viagra buy generic lisinopril
academicwriting blackjack online real money doubleu casino online casino
help with assignments uk paperwriter sildenafil overnight
cheap clomid buy ventolin 4mg online cheap online poker real money
buy orlistat generic diltiazem 180mg cheap purchase acyclovir pill
cialis from canada online cialis plavix pills
zyloprim uk zetia 10mg oral generic ezetimibe 10mg
order cozaar 50mg generic topamax 100mg canada topiramate 100mg tablet
baclofen tablet order tizanidine online cheap toradol generic
colchicine drug live blackjack play blackjack online
tamsulosin 0.4mg pills tamsulosin buy online aldactone 100mg us
buy cialis 40mg online real cialis fast shipping cipro 500mg without prescription
metronidazole 400mg sale purchase flagyl online buy bactrim online
cost tadalafil 10mg order cialis 5mg without prescription canadian viagra online pharmacy
buy viagra 100mg sale viagra for men order cialis
buy trazodone 100mg online suhagra 50mg canada buy aurogra 100mg for sale
best casino slot games low cost ed pills buy tadalafil pills
azithromycin 250mg sale order zithromax 500mg order neurontin 100mg generic
order tretinoin cream online buy retin online cheap generic avana 100mg
naprosyn 500mg oral purchase naprosyn for sale buy lansoprazole 30mg online cheap
albuterol price purchase ciprofloxacin ciprofloxacin cheap
singulair 10mg ca buy sildenafil 50mg online cheap viagra for sale
actos 15mg price pfizer viagra 50mg buy sildenafil 50mg for sale
buy tadalafil 10mg online tadalafil 10mg pill order cialis 20mg
tadalafil india Buy cialis low price free online blackjack
order adalat online cheap fexofenadine 180mg us brand allegra 180mg
buy doxycycline 100mg online cheap order cleocin 300mg generic buy cleocin 300mg sale
custom dissertation services azulfidine 500mg pills buy azulfidine 500mg generic
olmesartan 20mg usa olmesartan price depakote canada
buy temovate for sale buspirone usa purchase amiodarone
acetazolamide 250mg canada order imuran 25mg without prescription azathioprine drug
buy lanoxin 250 mg online cheap purchase digoxin for sale cheap molnupiravir 200 mg
carvedilol order order coreg 6.25mg pill elavil 10mg sale
buy amoxicillin 500mg online purchase stromectol pills ivermectin tablets order
buy dapoxetine 90mg online order avanafil 100mg pill order motilium 10mg for sale
pamelor 25mg ca paracetamol for sale online buy paxil 10mg online
famotidine 20mg canada brand mirtazapine remeron 30mg drug
purchase requip without prescription brand ropinirole 2mg trandate 100 mg without prescription
tadalafil 10mg price tadacip over the counter trimox 500mg without prescription
buy minocycline 50mg generic order generic hytrin 1mg hytrin for sale
order clomid 100mg sale buy atorvastatin sale prednisolone pill
cost ivermectin stromectol 12mg canada brand prednisone 20mg
isotretinoin 40mg generic purchase amoxil pills azithromycin 250mg pill
purchase vibra-tabs pills order levitra 10mg online acyclovir 400mg canada