This function will be start running the program. it also should be implemented by derived classes.
454 #ifndef CV_VERSION_EPOCH // version 3 or newer 456 cv::cuda::GpuMat d_currentReference8, d_currentGroupAverage8;
458 cv::gpu::GpuMat d_flowx, d_flowy, d_currentReference8, d_currentGroupAverage8;
465 cv::Mat cvCurrentReference, cvNewReference, cvCurrentGroupAverage, cvUndeformedGroupAverage, cvCurrentGroupAverage8, cvCurrentReference8;
466 cv::Mat flowxCurrentGroup, flowyCurrentGroup, flowxPreviousGroup, flowyPreviousGroup;
467 cv::Mat flowCurrentGroup[]={flowxCurrentGroup, flowyCurrentGroup};
468 cv::Mat flowPreviousGroup[]={flowxPreviousGroup, flowyPreviousGroup};
472 #ifndef CV_VERSION_EPOCH // version 3 or newer 474 cv::Ptr<cv::cuda::FarnebackOpticalFlow> d_calc = cv::cuda::FarnebackOpticalFlow::create(
486 cv::gpu::FarnebackOpticalFlow d_calc;
490 d_calc.fastPyramids=
true;
494 d_calc.polySigma=1.1;
503 cout <<
"Frames " <<
nfirst <<
" to " <<
nlast <<
" under processing ..." << std::endl;
505 int numberOfGroups=2;
508 while (levelCounter<levelNum)
512 d_currentReference8.upload(cvCurrentReference8);
514 int currentGroupSize=int(ceil((
float)
numberOfFrames/numberOfGroups));
516 bool lastLevel = levelCounter==levelNum-1;
518 cvNewReference=cv::Mat::zeros(
Ydim,
Xdim, CV_32FC1);
520 cout <<
"Level " << levelCounter <<
"/" << levelNum-1
521 <<
" of the pyramid is under processing" << std::endl;
522 cout <<
" Group size: " << currentGroupSize <<
", Number of groups: " << numberOfGroups << std::endl;
525 clock_t tStart = clock();
527 for (
int currentGroup=0; currentGroup<numberOfGroups; currentGroup++)
529 int NimgsInAvg=
computeAvg(currentGroup*currentGroupSize+
nfirst, (currentGroup+1)*currentGroupSize+
nfirst-1, cvCurrentGroupAverage);
534 if (numberOfGroups>2)
537 readMat(flowXFileName.c_str(), flowCurrentGroup[0]);
541 readMat(flowYFileName.c_str(), flowCurrentGroup[1]);
545 d_currentGroupAverage8.upload(cvCurrentGroupAverage8);
546 #ifndef CV_VERSION_EPOCH // version 3 or newer 547 cv::cuda::GpuMat d_flow(cvCurrentGroupAverage8.size(), CV_32FC2);
548 cv::cuda::GpuMat planes[2];
549 if (numberOfGroups>2)
551 cv::cuda::split(d_flow, planes);
552 planes[0].upload(flowCurrentGroup[0]);
553 planes[1].upload(flowCurrentGroup[1]);
554 d_calc->setFlags(cv::OPTFLOW_USE_INITIAL_FLOW);
556 d_calc->calc(d_currentReference8, d_currentGroupAverage8, d_flow);
558 cv::cuda::split(d_flow, planes);
559 planes[0].download(flowCurrentGroup[0]);
560 planes[1].download(flowCurrentGroup[1]);
562 if (numberOfGroups>2)
564 d_flowx.upload(flowCurrentGroup[0]);
565 d_flowy.upload(flowCurrentGroup[1]);
566 d_calc.flags=cv::OPTFLOW_USE_INITIAL_FLOW;
568 d_calc(d_currentReference8, d_currentGroupAverage8, d_flowx, d_flowy);
569 d_flowx.download(flowCurrentGroup[0]);
570 d_flowy.download(flowCurrentGroup[1]);
571 d_currentGroupAverage8.release();
578 if (numberOfGroups==2)
580 flowxCurrentGroup=cv::Mat::zeros(
Ydim,
Xdim, CV_32FC1);
581 flowyCurrentGroup=cv::Mat::zeros(
Ydim,
Xdim, CV_32FC1);
582 flow=cv::Mat::zeros(
Ydim,
Xdim, CV_32FC1);
585 ofFlags=cv::OPTFLOW_USE_INITIAL_FLOW;
587 merge(flowCurrentGroup,2,flow);
589 calcOpticalFlowFarneback(cvCurrentReference8, cvCurrentGroupAverage8, flow, 0.5, 6,
winSize, 1, 5, 1.1, ofFlags);
590 split(flow, flowCurrentGroup);
596 if (currentGroup > 0)
605 flowCurrentGroup[0].copyTo(flowPreviousGroup[0]);
606 flowCurrentGroup[1].copyTo(flowPreviousGroup[1]);
612 saveMat(flowXFileName.c_str(), flowCurrentGroup[0]);
613 saveMat(flowYFileName.c_str(), flowCurrentGroup[1]);
625 for (
float row = 0; row < flowCurrentGroup[0].rows; row++ )
626 for (
float col = 0;
col < flowCurrentGroup[0].cols;
col++ )
628 flowCurrentGroup[0].at<
float>(row,
col) +=
col;
629 flowCurrentGroup[1].at<
float>(row,
col) += row;
631 cv::remap(cvCurrentGroupAverage, cvUndeformedGroupAverage, flowCurrentGroup[0], flowCurrentGroup[1], cv::INTER_CUBIC);
657 opencv2Xmipp(cvUndeformedGroupAverage,undeformedGroupAverage());
664 cv::Mat cvFrame, cvUndeformedFrame;
667 cv::remap(cvFrame, cvUndeformedFrame, flowCurrentGroup[0], flowCurrentGroup[1], cv::INTER_CUBIC);
672 uncompensatedMic()=frame();
674 uncompensatedMic()+=frame();
677 cvNewReference+=cvUndeformedGroupAverage;
680 d_currentReference8.release();
682 cvCurrentReference=cvNewReference;
683 cvCurrentReference*=1.0/numberOfGroups;
687 printf(
"Processing time: %.2fs\n", (
double)(clock() - tStart)/CLOCKS_PER_SEC);
void min(Image< double > &op1, const Image< double > &op2)
void applyDoseFilterToImage(int Ydim, int Xdim, const MultidimArray< std::complex< double > > &FFT1, const double dose_start, const double dose_finish)
Apply a dose filter to the image Fourier transform.
FileName removeLastExtension() const
void write(const FileName &name="", size_t select_img=ALL_IMAGES, bool isStack=false, int mode=WRITE_OVERWRITE, CastWriteMode castMode=CW_CAST, int _swapWrite=0)
void convert2Uint8(cv::Mat opencvDoubleMat, cv::Mat &opencvUintMat)
ProgMovieFilterDose * filterDose
void evaluateDisplacements(const cv::Mat *flowCurrentGroup, const cv::Mat *flowPreviousGroup, Matrix1D< double > &meanStdDev)
void log(Image< double > &op)
FourierTransformer transformer
void saveMat(const FileName &fnOut, const cv::Mat &M)
void readMat(const FileName &fnIn, cv::Mat &M)
void removeFlows(int level)
void opencv2Xmipp(const cv::Mat &opencvMat, MultidimArray< float > &xmippArray)
void typeCast(const Matrix1D< T1 > &v1, Matrix1D< T2 > &v2)
void xmipp2Opencv(const MultidimArray< float > &xmippArray, cv::Mat &opencvMat)
String formatString(const char *format,...)
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
int computeAvg(size_t begin, size_t end, cv::Mat &cvAvgImg)