Path: blob/master/apps/interactive-calibration/calibPipeline.cpp
16337 views
// This file is part of OpenCV project.1// It is subject to the license terms in the LICENSE file found in the top-level directory2// of this distribution and at http://opencv.org/license.html.34#include "calibPipeline.hpp"56#include <opencv2/highgui.hpp>78#include <stdexcept>910using namespace calib;1112#define CAP_DELAY 101314cv::Size CalibPipeline::getCameraResolution()15{16mCapture.set(cv::CAP_PROP_FRAME_WIDTH, 10000);17mCapture.set(cv::CAP_PROP_FRAME_HEIGHT, 10000);18int w = (int)mCapture.get(cv::CAP_PROP_FRAME_WIDTH);19int h = (int)mCapture.get(cv::CAP_PROP_FRAME_HEIGHT);20return cv::Size(w,h);21}2223CalibPipeline::CalibPipeline(captureParameters params) :24mCaptureParams(params)25{2627}2829PipelineExitStatus CalibPipeline::start(std::vector<cv::Ptr<FrameProcessor> > processors)30{31if(mCaptureParams.source == Camera && !mCapture.isOpened())32{33mCapture.open(mCaptureParams.camID);34cv::Size maxRes = getCameraResolution();35cv::Size neededRes = mCaptureParams.cameraResolution;3637if(maxRes.width < neededRes.width) {38double aR = (double)maxRes.width / maxRes.height;39mCapture.set(cv::CAP_PROP_FRAME_WIDTH, neededRes.width);40mCapture.set(cv::CAP_PROP_FRAME_HEIGHT, neededRes.width/aR);41}42else if(maxRes.height < neededRes.height) {43double aR = (double)maxRes.width / maxRes.height;44mCapture.set(cv::CAP_PROP_FRAME_HEIGHT, neededRes.height);45mCapture.set(cv::CAP_PROP_FRAME_WIDTH, neededRes.height*aR);46}47else {48mCapture.set(cv::CAP_PROP_FRAME_HEIGHT, neededRes.height);49mCapture.set(cv::CAP_PROP_FRAME_WIDTH, neededRes.width);50}51mCapture.set(cv::CAP_PROP_AUTOFOCUS, 0);52}53else if (mCaptureParams.source == File && !mCapture.isOpened())54mCapture.open(mCaptureParams.videoFileName);55mImageSize = cv::Size((int)mCapture.get(cv::CAP_PROP_FRAME_WIDTH), (int)mCapture.get(cv::CAP_PROP_FRAME_HEIGHT));5657if(!mCapture.isOpened())58throw std::runtime_error("Unable to open video source");5960cv::Mat frame, processedFrame;61while(mCapture.grab()) {62mCapture.retrieve(frame);63if(mCaptureParams.flipVertical)64cv::flip(frame, frame, -1);6566frame.copyTo(processedFrame);67for (std::vector<cv::Ptr<FrameProcessor> >::iterator it = processors.begin(); it != processors.end(); ++it)68processedFrame = (*it)->processFrame(processedFrame);69cv::imshow(mainWindowName, processedFrame);70char key = (char)cv::waitKey(CAP_DELAY);7172if(key == 27) // esc73return Finished;74else if (key == 114) // r75return DeleteLastFrame;76else if (key == 100) // d77return DeleteAllFrames;78else if (key == 115) // s79return SaveCurrentData;80else if (key == 117) // u81return SwitchUndistort;82else if (key == 118) // v83return SwitchVisualisation;8485for (std::vector<cv::Ptr<FrameProcessor> >::iterator it = processors.begin(); it != processors.end(); ++it)86if((*it)->isProcessed())87return Calibrate;88}8990return Finished;91}9293cv::Size CalibPipeline::getImageSize() const94{95return mImageSize;96}979899