Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/apps/interactive-calibration/calibPipeline.cpp
16337 views
1
// This file is part of OpenCV project.
2
// It is subject to the license terms in the LICENSE file found in the top-level directory
3
// of this distribution and at http://opencv.org/license.html.
4
5
#include "calibPipeline.hpp"
6
7
#include <opencv2/highgui.hpp>
8
9
#include <stdexcept>
10
11
using namespace calib;
12
13
#define CAP_DELAY 10
14
15
cv::Size CalibPipeline::getCameraResolution()
16
{
17
mCapture.set(cv::CAP_PROP_FRAME_WIDTH, 10000);
18
mCapture.set(cv::CAP_PROP_FRAME_HEIGHT, 10000);
19
int w = (int)mCapture.get(cv::CAP_PROP_FRAME_WIDTH);
20
int h = (int)mCapture.get(cv::CAP_PROP_FRAME_HEIGHT);
21
return cv::Size(w,h);
22
}
23
24
CalibPipeline::CalibPipeline(captureParameters params) :
25
mCaptureParams(params)
26
{
27
28
}
29
30
PipelineExitStatus CalibPipeline::start(std::vector<cv::Ptr<FrameProcessor> > processors)
31
{
32
if(mCaptureParams.source == Camera && !mCapture.isOpened())
33
{
34
mCapture.open(mCaptureParams.camID);
35
cv::Size maxRes = getCameraResolution();
36
cv::Size neededRes = mCaptureParams.cameraResolution;
37
38
if(maxRes.width < neededRes.width) {
39
double aR = (double)maxRes.width / maxRes.height;
40
mCapture.set(cv::CAP_PROP_FRAME_WIDTH, neededRes.width);
41
mCapture.set(cv::CAP_PROP_FRAME_HEIGHT, neededRes.width/aR);
42
}
43
else if(maxRes.height < neededRes.height) {
44
double aR = (double)maxRes.width / maxRes.height;
45
mCapture.set(cv::CAP_PROP_FRAME_HEIGHT, neededRes.height);
46
mCapture.set(cv::CAP_PROP_FRAME_WIDTH, neededRes.height*aR);
47
}
48
else {
49
mCapture.set(cv::CAP_PROP_FRAME_HEIGHT, neededRes.height);
50
mCapture.set(cv::CAP_PROP_FRAME_WIDTH, neededRes.width);
51
}
52
mCapture.set(cv::CAP_PROP_AUTOFOCUS, 0);
53
}
54
else if (mCaptureParams.source == File && !mCapture.isOpened())
55
mCapture.open(mCaptureParams.videoFileName);
56
mImageSize = cv::Size((int)mCapture.get(cv::CAP_PROP_FRAME_WIDTH), (int)mCapture.get(cv::CAP_PROP_FRAME_HEIGHT));
57
58
if(!mCapture.isOpened())
59
throw std::runtime_error("Unable to open video source");
60
61
cv::Mat frame, processedFrame;
62
while(mCapture.grab()) {
63
mCapture.retrieve(frame);
64
if(mCaptureParams.flipVertical)
65
cv::flip(frame, frame, -1);
66
67
frame.copyTo(processedFrame);
68
for (std::vector<cv::Ptr<FrameProcessor> >::iterator it = processors.begin(); it != processors.end(); ++it)
69
processedFrame = (*it)->processFrame(processedFrame);
70
cv::imshow(mainWindowName, processedFrame);
71
char key = (char)cv::waitKey(CAP_DELAY);
72
73
if(key == 27) // esc
74
return Finished;
75
else if (key == 114) // r
76
return DeleteLastFrame;
77
else if (key == 100) // d
78
return DeleteAllFrames;
79
else if (key == 115) // s
80
return SaveCurrentData;
81
else if (key == 117) // u
82
return SwitchUndistort;
83
else if (key == 118) // v
84
return SwitchVisualisation;
85
86
for (std::vector<cv::Ptr<FrameProcessor> >::iterator it = processors.begin(); it != processors.end(); ++it)
87
if((*it)->isProcessed())
88
return Calibrate;
89
}
90
91
return Finished;
92
}
93
94
cv::Size CalibPipeline::getImageSize() const
95
{
96
return mImageSize;
97
}
98
99