void RApplication::writeVideo() { char drive[_MAX_DRIVE]; char dir[_MAX_DIR]; char fname[_MAX_FNAME]; char ext[_MAX_EXT]; _splitpath_s( Pubvar::videoPath.c_str(), drive, dir, fname, ext); string outputPath = ""; int start = 0, end = 0, idx = 0, winsize = 8 * fps; VideoWriter writer; VideoCapture capCut; CV_Assert(capCut.open(Pubvar::videoPath)); Mat cutFrame; for (int i = winsize; i < videoLen; ++i) { if(fidOI[i]) { outputPath = "data/" + (string)fname + "_" + to_string(idx++) + ext; writer = VideoWriter(outputPath, CV_FOURCC('D', 'I', 'V', '3') , fps, frame.size()); capCut.set(CV_CAP_PROP_POS_FRAMES, i-winsize); for(int j=i-winsize ; j<=i ; j++) { capCut >> cutFrame; writer << cutFrame; } writer.release(); } } }
// Prepare videowriter to capture camera bool ProcessingThread::startRecord(std::string filepath, bool captureOriginal) { // release Video if any was made until now releaseCapture(); // Initials for the VideoWriter // Size int w = (int)currentROI.width; int h = (int)currentROI.height; // Codec WATCH OUT: Not every codec is available on every PC, // MP4V was chosen because it's famous among various systems //int codec = CV_FOURCC('M','P','4','V'); // Check if grayscale is on (or camera only captures grayscale) bool isColor = !((imgProcFlags.grayscaleOn)||(currentFrame.channels() == 1)); // Capture size is doubled if original should be captured too Size s = captureOriginal ? Size(w*2, h) : Size(w, h); bool opened = false; output = VideoWriter(); opened = output.open(filepath, savingCodec, statsData.averageFPS, s, isColor); recordingFramerate = statsData.averageFPS; if(opened) { this->doRecord = true; this->captureOriginal = captureOriginal; } return opened; }
void kuwaharaFilter::videoFilter(const string &src_path, const string &dst_path) { VideoCapture v_reader = VideoCapture(src_path.c_str()); double reszie_ratio = 1.0; if ( v_reader.isOpened() ) { Mat temp; v_reader >> temp; resizeMat(temp, reszie_ratio); VideoWriter v_writer = VideoWriter(dst_path.c_str(), CV_FOURCC('P','I','M','1'), 30, temp.size()); while (v_reader.grab()) { resizeMat(temp, reszie_ratio); temp = imageFilter(temp, 3); temp.convertTo(temp, CV_8UC3); v_writer.write(temp); v_reader >> temp; } v_writer.release(); }
// Constructor SavingThread::SavingThread() : QThread() { this->doStop = true; currentWriteIndex = 0; processingBufferLength = 1; cap = VideoCapture(); out = VideoWriter(); }
ProcessingThread::ProcessingThread(SharedImageBuffer *sharedImageBuffer, int deviceNumber) : QThread(), sharedImageBuffer(sharedImageBuffer), emitOriginal(false) { // Save Device Number this->deviceNumber=deviceNumber; // Initialize members doStop=false; doRecord=false; sampleNumber=0; fpsSum=0; framesWritten = 0; fps.clear(); statsData.averageFPS=0; statsData.nFramesProcessed=0; captureOriginal = false; this->processingBufferLength = 2; this->magnificator = Magnificator(&processingBuffer, &imgProcFlags, &imgProcSettings); this->output = VideoWriter(); }
int main(int argc, char* argv[]) { cuerpo humano; bool grabarmeneada = false; bool calibrationMode = false; Mat cameraFeed; Mat threshold; Mat HSV; cv::Size frameSize(FRAME_WIDTH, FRAME_HEIGHT); Mat figura= Mat::zeros(frameSize, CV_8UC1); vector<Mat> spl; if(calibrationMode){ createTrackbars(); } VideoCapture captura; captura.open(1); // cv::VideoWriter grabar; //figura = Mat::zeros(frameSize, CV_8UC1); if(grabarmeneada){ string filename = "meneate.avi"; //fcc int fcc = CV_FOURCC('D','I','V','3'); int fps = 10; grabar = VideoWriter(filename, fcc, fps, frameSize); if(!grabar.isOpened()){ cout<<"ERROR al grabar archivo"<<endl; getchar(); return -1; } } captura.set(CV_CAP_PROP_FRAME_WIDTH,FRAME_WIDTH); captura.set(CV_CAP_PROP_FRAME_HEIGHT,FRAME_HEIGHT); while(1){ captura.read(cameraFeed); cvtColor(cameraFeed,HSV,COLOR_BGR2HSV); if(calibrationMode==true){ cvtColor(cameraFeed,HSV,COLOR_BGR2HSV); inRange(HSV,Scalar(H_MIN,S_MIN,V_MIN),Scalar(H_MAX,S_MAX,V_MAX),threshold); morphOps(threshold); imshow(windowName2,threshold); trackFilteredObject(threshold,HSV,cameraFeed,figura, humano); }else{ nodo marca; marca.setHSVmin(Scalar(24,2,240)); marca.setHSVmax(Scalar(85,115,256)); cvtColor(cameraFeed,HSV,COLOR_BGR2HSV); inRange(HSV,marca.getHSVmin(),marca.getHSVmax(),threshold); morphOps(threshold); trackFilteredObject(threshold,HSV,cameraFeed,figura, humano); if(grabarmeneada){ split(cameraFeed, spl); for (int i =0; i < 3; ++i) spl[i] = figura; merge(spl, figura); grabar.write(figura); } } imshow(windowName2,threshold); imshow(windowName,cameraFeed); grabar.write(figura); imshow(meneate,figura); //imshow(windowName1,HSV); switch(waitKey(1)){ case 27://ESC return 0; } waitKey(10); } return 0; }