วันศุกร์ที่ 23 ธันวาคม พ.ศ. 2559

OPENCV : 9. Write Video





#include <iostream>

#include "opencv2/highgui/highgui.hpp"

#include "opencv2/imgproc/imgproc.hpp"

#include "opencv2/imgcodecs/imgcodecs.hpp"

#include "opencv2/videoio/videoio.hpp"



int main(int argc, char** argv)
{

cv::VideoCapture videoCapture("music.mp4");

cv::Mat frame;

int countFrame = 0;

int numberOfAllFrame = videoCapture.get(CV_CAP_PROP_FRAME_COUNT);

double frameRate = videoCapture.get(CV_CAP_PROP_FPS);

std::cout << "Framerate : " << frameRate << std::endl;


cv::Mat frame_bgra;

cv::VideoWriter outputVideo("out.wmv", CV_FOURCC('W', 'M', 'V', '2'), frameRate, cv::Size(800, 600), true);


while (countFrame < numberOfAllFrame)
{


videoCapture >> frame;

cv::cvtColor(frame, frame_bgra, CV_BGR2BGRA);

// find all white pixel and set alpha value to zero:
for (int y = 0; y < frame_bgra.rows; ++y)
for (int x = 0; x < frame_bgra.cols; ++x)
{
cv::Vec4b & pixel = frame_bgra.at<cv::Vec4b>(y, x);
// if pixel is black
if (pixel[0] < 10 && pixel[1] < 10 && pixel[2] < 10)
{
// set alpha to zero:
pixel[3] = 0;
}
}

outputVideo << frame_bgra;



std::cout << "----> " << ( (float)countFrame / numberOfAllFrame ) * 100 << " %" << std::endl;

countFrame++;


}

std::cout << "OKKKKK" << std::endl;


}

ไม่มีความคิดเห็น:

แสดงความคิดเห็น