本文整理汇总了C++中VideoWriter::open方法的典型用法代码示例。如果您正苦于以下问题:C++ VideoWriter::open方法的具体用法?C++ VideoWriter::open怎么用?C++ VideoWriter::open使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VideoWriter
的用法示例。
在下文中一共展示了VideoWriter::open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MakeVideoLocally
void MakeVideoLocally()
{
CvSize init_size;
Mat img1 = imread("D:/TDDOWNLOAD/GDown/473/473/1/1.bmp");
Mat img2 = imread("D:/TDDOWNLOAD/GDown/473/473/1/2.bmp");
Mat img3 = imread("D:/TDDOWNLOAD/GDown/473/473/1/3.bmp");
Mat img4 = imread("D:/TDDOWNLOAD/GDown/473/473/1/4.bmp");
init_size = cvSize(img1.size().width, img1.size().height);
namedWindow("img1", 1);
imshow("img1", img1);
namedWindow("img2", 1);
imshow("img2", img2);
namedWindow("img3", 1);
imshow("img3", img3);
namedWindow("img4", 1);
imshow("img4", img4);
waitKey(0);
VideoWriter saveVideoWriter;
saveVideoWriter.open("source.avi", CV_FOURCC('X', 'V', 'I', 'D'), 1, init_size, true) ;
saveVideoWriter<<img1;
saveVideoWriter<<img2;
saveVideoWriter<<img3;
saveVideoWriter<<img4;
}
示例2: calcularHistogramaAcumulatOF
/* Funció que calcula l'histograma acumulat de cada una de les execucions d'una activitat */
Mat HistogramaOF::calcularHistogramaAcumulatOF(String path, int num_imatges, String nom_activitat, int num_repeticio, string ruta, bool video) {
String nomVideo, nomImatgeRGBa, nomImatgeDa, nomImatgeRGBb, nomImatgeDb;
VideoWriter outputVideo;
if(video) {
double fps = 15;
CvSize mida = cvSize(399, 240);
nomVideo = ruta+"/"+nom_activitat+"_acumulat_"+to_string(num_repeticio)+".avi";
outputVideo.open(nomVideo, 0, fps, mida, true);
}
Mat imageA, depthA, imageB, depthB, resultat;
nomImatgeRGBa = path+"/c_0.png";
nomImatgeDa = path+"/d_0.png";
imageA = imread(nomImatgeRGBa, IMREAD_COLOR);
depthA = imread(nomImatgeDa, IMREAD_GRAYSCALE);
resultat = calcularHistogramaOF(imageA, imageA, depthA, depthA);
if(video) outputVideo << resultat;
for(int k = 1; k <= num_imatges; ++k) {
cout << "Imatge: " << num_repeticio << " - " << k << "/" << num_imatges << endl;
nomImatgeRGBb = path+"/c_"+to_string(k)+".png";
nomImatgeDb = path+"/d_"+to_string(k)+".png";
imageB = imread(nomImatgeRGBb, IMREAD_COLOR);
depthB= imread(nomImatgeDb, IMREAD_GRAYSCALE);
resultat = calcularHistogramaOF(imageA, imageB, depthA, depthB);
if(video) outputVideo << resultat;
nomImatgeRGBa = nomImatgeRGBb;
nomImatgeDa = nomImatgeDb;
imageB.copyTo(imageA);
depthB.copyTo(depthA);
}
if(video) outputVideo.release();
return repr;
}
示例3: main
/** start the camera and hand over the variable to the function detectAndDisplay*/
int main( int argc, const char** argv ) {
Mat frame; /** 2D or multi-dimensional dense array for frame*/
char c; /** definition for close the Video - Surveillance GUI */
if( !LoadHaarClassifier() || cascade )
{
VideoCapture capture(-1); /** open the default camera */
if( !capture.isOpened() ){ cout << "\nCamera couldn't be opened!" << endl; return -1; }
capture >> frame; /** get frame for size */
/** record video */
record.open("Record.avi", CV_FOURCC('D','I','V','X'), 30, frame.size(), true);
if( !record.isOpened() ) { cout << "\nCamera couldn't be opened!"<< endl; return -1; }
while(true)
{
/** new frame from Camera */
capture >> frame;
/** Apply the classifier to the frame */
if( !frame.empty() )
{
/** call the function to detect, save and write detected faces, */
detectAndDisplay( frame );
}
/** Press Esc to close face detection */
c = cvWaitKey(33); /** The 33 number in the code means that after 33ms, a new frame would be shown. */
if( c == 27 ) { break; } /** 27 is the Ascii Code for Esc*/
}
}
示例4: processVideo
void HOGDetectorGPU::processVideo(char* ptrNameInput, char* ptrNameOutput){
VideoCapture inputVideo(ptrNameInput);
VideoWriter outputVideo;
Size sizeVideo = Size((int) inputVideo.get(CV_CAP_PROP_FRAME_WIDTH),(int) inputVideo.get(CV_CAP_PROP_FRAME_HEIGHT));
Mat* ptrMatOut;
outputVideo.open(ptrNameOutput, CV_FOURCC('x','v','i','d'), inputVideo.get(CV_CAP_PROP_FPS), sizeVideo, true);
Mat* ptrMat;
vector<Mat> spl;
while(inputVideo.grab()){
ptrMat = new Mat();
inputVideo >> *ptrMat; // get a new frame from video
Mat finalMat;
split(*ptrMat, spl);
cvtColor(*ptrMat, *ptrMat, CV_BGR2GRAY);
ptrMatOut = detectPeople(ptrMat);
spl[0] = *(ptrMatOut);
spl[1] = *(ptrMatOut);
spl[2] = *(ptrMatOut);
merge(spl, finalMat);
outputVideo << finalMat;
imshow("edges", *(ptrMatOut));
if(waitKey(30) >= 0) break;
//Deletes the processed frame
delete ptrMatOut;
}
outputVideo.release();
}
示例5: imshow
void Converter::saveTCMat2RGBVideo(char* resultDir, TCVectorizedVidMat& data){
VideoWriter outputVideo;
outputVideo.open(resultDir, data.ex, data.fps, data.size, true);
if (!outputVideo.isOpened()){
cout << "cannot save video." << endl;
throw 1;
}
cout << "start save"<<endl;
for (int i = 0 ; i < data.nMat ; ++i){
// Devectorization
cout << i << endl;
TCMat frame;
frame.rows = data.rows;
frame.cols = data.cols;
frame.green = data.green.col(i);
frame.green.reshape(data.rows, data.cols);
frame.red = data.red.col(i);
frame.red.reshape(data.rows, data.cols);
frame.blue = data.blue.col(i);
frame.blue.reshape(data.rows, data.cols);
cv::Mat img = TCMat2RGB(frame);
imshow("Video", img);
int key = waitKey(10);
if((char)key == 'q') { break; }
outputVideo << img;
}
return;
}
示例6: on_cmdRun_clicked
void MainWindow::on_cmdRun_clicked()
{
if (selectedFile != "")
{
VideoCapture vid(selectedFile.toStdString().c_str());
VideoWriter vout;
vout.open((selectedFile + "out.mpeg").toStdString().c_str(),CV_FOURCC('M','P','E','G'),30,Size(vid.get(CV_CAP_PROP_FRAME_WIDTH), vid.get(CV_CAP_PROP_FRAME_HEIGHT)));
qDebug() << "Frame cnt " << frame_count;
QFileInfo filedir = QFileInfo(selectedFile);
QDir currdir = filedir.dir();
int sample_size = frame_count;
if (sample_size <= 0)
return;
int sample_interval = frame_count / sample_size;
int sample_cnt = 0;
ui->prog->setMaximum(frame_count);
bool undistorted = ui->chkDistort->isChecked();
Mat cammatrix;
Mat distortion;
double rms;
if (undistorted)
{
FileStorage file(calibFile.toStdString().c_str(),FileStorage::READ);
file["rms"] >> rms;
file["cameramatrix"] >> cammatrix;
file["distortion"] >> distortion;
}
for (int i = 0; i < frame_count; i++)
{
Mat r;
vid >> r;
QString writepath = selectedFile + "-" + QString::number(i) + ".png";
Mat c;
if (undistorted)
{
undistort(r, c, cammatrix, distortion);
}
else
{
c = r;
}
imwrite(writepath.toStdString().c_str(), c);
vout << c;
ui->prog->setValue(i);
}
ui->prog->setValue(frame_count);
}
示例7: initializeVideoWriter
void initializeVideoWriter(const char* fileName, int width, int height, int fps) {
Size size = Size(width, height);
//int fourcc = VideoWriter::fourcc('F','L','V','1');
int fourcc = CV_FOURCC('F', 'L', 'V', '1');
bool opened = videoWriter.open(fileName, fourcc, fps, size, true);
printf("video opened=%d %dx%d %d fps\n", opened, width, height, fps);
videoWriterReleased=0;
}
示例8: initVideoWriter
void initVideoWriter(CvCapture *inputVideo, string source, string addStr)
{
string::size_type pAt = source.find_last_of('.'); // Find extension point
const string NAME = source.substr(0, pAt) + addStr + ".avi"; // Form the new name with container
Size S = Size((int) cvGetCaptureProperty(inputVideo, CV_CAP_PROP_FRAME_WIDTH), //Acquire input size
(int) cvGetCaptureProperty(inputVideo, CV_CAP_PROP_FRAME_HEIGHT));
outputVideo.open(NAME , -1, cvGetCaptureProperty(inputVideo, CV_CAP_PROP_FPS) * 3 /3,S, true);
CV_Assert(outputVideo.isOpened() == true);
}
示例9: main
int main(int argc, char* argv[])
{
VideoCapture cap("joker.avi"); // open the video file for reading
if (!cap.isOpened()) // if not success, exit program
{
cout << "Cannot open the video file" << endl;
return -1;
}
//cap.set(CV_CAP_PROP_POS_MSEC, 200); //start the video at 300ms
double fps = cap.get(CV_CAP_PROP_FPS); //get the frames per seconds of the video
double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH); //get the width of frames of the video
double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT); //get the height of frames of the video
int ex = static_cast<int>(cap.get(CV_CAP_PROP_FOURCC)); // Get Codec Type- Int form
cout << "Frame per seconds : " << fps << endl;
cout << "Frame size : " << dWidth << " x " << dHeight << endl;
cout << "Codec type of the video : " << ex << endl;
int askFileTypeBox = cap.get(CV_CAP_PROP_FOURCC); //-1 is show box of codec
int Color = 1;
Size S = Size((int)cap.get(CV_CAP_PROP_FRAME_WIDTH),
(int)cap.get(CV_CAP_PROP_FRAME_HEIGHT));
VideoWriter outputVideo;
outputVideo.open(".\\outVideo.avi", -1, cap.get(CV_CAP_PROP_FPS), S, Color);
//namedWindow("MyVideo", CV_WINDOW_AUTOSIZE); //create a window called "MyVideo"
//while (1)
//{
// Mat frame;
// bool bSuccess = cap.read(frame); // read a new frame from video
// if (!bSuccess) //if not success, break loop
// {
// cout << "Cannot read the frame from video file" << endl;
// break;
// }
// imshow("MyVideo", frame); //show the frame in "MyVideo" window
if (waitKey(30) == 27) //wait for 'esc' key press for 30 ms. If 'esc' key is pressed, break loop
{
cout << "esc key is pressed by user" << endl;
// break;
}
//}
return 0;
}
示例10: main
int main( int argc, char* argv[] )
{
if(argc > 2)
NOWRITE = 0;
cout << "nowrite = " << NOWRITE << endl;
namedWindow( "Example2_10", CV_WINDOW_AUTOSIZE );
namedWindow( "Log_Polar", CV_WINDOW_AUTOSIZE );
Mat bgr_frame;
VideoCapture capture;
if( argc < 2 || !capture.open( argv[1] ) ){
help();
cout << "Failed to open " << argv[1] << "\n" << endl;
return -1;
}
double fps = capture.get(CV_CAP_PROP_FPS);
cout << "fps = " << fps << endl;
Size size((int)capture.get(CV_CAP_PROP_FRAME_WIDTH),
(int)capture.get(CV_CAP_PROP_FRAME_HEIGHT));
cout << " frame (w, h) = (" << size.width << ", " << size.height << ")" <<endl;
VideoWriter writer;
if(! NOWRITE)
{ writer.open( // On linux Will only work if you've installed ffmpeg development files correctly,
argv[2], // otherwise segmentation fault. Windows probably better.
CV_FOURCC('M','J','P','G'),
fps,
size
);
}
Mat logpolar_frame(size,CV_8UC3);
Mat gray_frame(size,CV_8UC1);
for(;;) {
capture >> bgr_frame;
if( bgr_frame.empty() ) break;
imshow( "Example2_10", bgr_frame );
cvtColor( //We never make use of this gray image
bgr_frame, gray_frame, CV_BGR2GRAY);
IplImage lp = logpolar_frame;
IplImage bgrf = bgr_frame;
cvLogPolar( &bgrf, &lp, //This is just a fun conversion the mimic's the human visual system
cvPoint2D32f(bgr_frame.cols/2,
bgr_frame.rows/2),
40,
CV_WARP_FILL_OUTLIERS );
imshow( "Log_Polar", logpolar_frame );
//Sigh, on linux, depending on your ffmpeg, this often won't work ...
if(! NOWRITE)
writer << logpolar_frame;
char c = waitKey(10);
if( c == 27 ) break;
}
capture.release();
}
示例11: main
int main(){
// Variables
VideoCapture capture;
VideoWriter writer;
Mat frame;
// Read from source
capture.open(0);
//capture.open("../Videos/chessboard-1.avi");
// Check if the source was opened correctly
if (!capture.isOpened()){
cout << "Cannot open video device or file!" << endl;
return -1;
}
// Read first frame (needed to configure VideoWriter)
capture.read(frame);
if (frame.empty()){
printf("VideoCapture failed getting the first frame!\n");
return -1;
}
// Open a video file for writing and check
writer.open("./video.avi", CV_FOURCC('D','I','V','X'), 15, frame.size(), true);
if( !writer.isOpened() ) {
printf("VideoWriter failed to open!\n");
return -1;
}
// Read the video
while(true){
// Read new frame
capture.read(frame);
if (frame.empty())
break;
// Write frame to a file
writer.write(frame);
// Show frame
imshow("video", frame);
if ((cvWaitKey(10) & 255) == 27) break;
}
// Release memory
capture.release();
frame.release();
return 0;
}
示例12: openForegroundVideoWithoutNoise
void openForegroundVideoWithoutNoise(const char* foregroundVideoWithoutNoisePath)
{
frameWithoutNoise = cvCreateImage(cvSize(foregroundVideoWidth, foregroundVideoHeight), IPL_DEPTH_8U, 3);
Size frameSize;
frameSize.width = foregroundVideoWidth;
frameSize.height = foregroundVideoHeight;
if(!foregroundVideoWithoutNoise.open(foregroundVideoWithoutNoisePath, CV_FOURCC('D', 'I', 'V', 'X'), foregroundVideoRate,frameSize, true))
{
printf("open foregroundVideoWriter error ...\n");
return;
}
}
示例13:
ImLogger::ImLogger(std::map<std::string,std::string> to_hook,double fps,cv::Size frame_size) : frame_size(frame_size) {
for(auto x : to_hook) {
VideoWriter wr;
wr.open
( x.second
, CV_FOURCC('F','M','P','4')
, fps
, frame_size);
hooks.insert(make_pair(x.first,wr));
}
}
示例14: VideoCapture
GenericClassnameOneTracker9000(string filename, string log_name, string output_path, bool extern_debug, bool extern_recording)
{
debug = extern_debug;
recording = extern_recording;
capture = VideoCapture(filename);
logger.open(log_name);
logger << filename << endl;
//int codec = static_cast<int>(inputVideo.get(CV_CAP_PROP_FOURCC));
Size frame_size = Size((int)capture.get(CV_CAP_PROP_FRAME_WIDTH),
(int)capture.get(CV_CAP_PROP_FRAME_HEIGHT));
tracking_recorder.open(output_path, CV_FOURCC('M', 'P', '4', '3'), capture.get(CV_CAP_PROP_FPS), frame_size);
}
示例15: main
int main(int, char**)
{
Mat src;
// use default camera as video source
VideoCapture cap(0);
// check if we succeeded
if (!cap.isOpened()) {
cerr << "ERROR! Unable to open camera\n";
return -1;
}
// get one frame from camera to know frame size and type
cap >> src;
// check if we succeeded
if (src.empty()) {
cerr << "ERROR! blank frame grabbed\n";
return -1;
}
bool isColor = (src.type() == CV_8UC3);
//--- INITIALIZE VIDEOWRITER
VideoWriter writer;
int codec = CV_FOURCC('M', 'J', 'P', 'G'); // select desired codec (must be available at runtime)
double fps = 25.0; // framerate of the created video stream
string filename = "./live.avi"; // name of the output video file
writer.open(filename, codec, fps, src.size(), isColor);
// check if we succeeded
if (!writer.isOpened()) {
cerr << "Could not open the output video file for write\n";
return -1;
}
//--- GRAB AND WRITE LOOP
cout << "Writing videofile: " << filename << endl
<< "Press any key to terminate" << endl;
for (;;)
{
// check if we succeeded
if (!cap.read(src)) {
cerr << "ERROR! blank frame grabbed\n";
break;
}
// encode the frame into the videofile stream
writer.write(src);
// show live and wait for a key with timeout long enough to show images
imshow("Live", src);
if (waitKey(5) >= 0)
break;
}
// the videofile will be closed and released automatically in VideoWriter destructor
return 0;
}