Merge pull request #22147 from rogday:zoom_factor

Add zoom factor to interactive calibration tool

* add zoom factor

* address review comments
This commit is contained in:
rogday 2022-06-30 23:31:52 +03:00 committed by GitHub
parent 2a4926f417
commit b91f173680
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 26 additions and 3 deletions

View File

@ -94,6 +94,7 @@ namespace calib
int maxFramesNum;
int minFramesNum;
bool saveFrames;
float zoom;
captureParameters()
{

View File

@ -5,6 +5,7 @@
#include "calibPipeline.hpp"
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <stdexcept>
@ -58,7 +59,7 @@ PipelineExitStatus CalibPipeline::start(std::vector<cv::Ptr<FrameProcessor> > pr
if(!mCapture.isOpened())
throw std::runtime_error("Unable to open video source");
cv::Mat frame, processedFrame;
cv::Mat frame, processedFrame, resizedFrame;
while(mCapture.grab()) {
mCapture.retrieve(frame);
if(mCaptureParams.flipVertical)
@ -67,7 +68,15 @@ PipelineExitStatus CalibPipeline::start(std::vector<cv::Ptr<FrameProcessor> > pr
frame.copyTo(processedFrame);
for (std::vector<cv::Ptr<FrameProcessor> >::iterator it = processors.begin(); it != processors.end(); ++it)
processedFrame = (*it)->processFrame(processedFrame);
cv::imshow(mainWindowName, processedFrame);
if (std::fabs(mCaptureParams.zoom - 1.) > 0.001f)
{
cv::resize(processedFrame, resizedFrame, cv::Size(), mCaptureParams.zoom, mCaptureParams.zoom);
}
else
{
resizedFrame = std::move(processedFrame);
}
cv::imshow(mainWindowName, resizedFrame);
char key = (char)cv::waitKey(CAP_DELAY);
if(key == 27) // esc

View File

@ -201,7 +201,16 @@ void CalibProcessor::showCaptureMessage(const cv::Mat& frame, const std::string
double textSize = VIDEO_TEXT_SIZE * frame.cols / (double) IMAGE_MAX_WIDTH;
cv::bitwise_not(frame, frame);
cv::putText(frame, message, textOrigin, 1, textSize, cv::Scalar(0,0,255), 2, cv::LINE_AA);
cv::imshow(mainWindowName, frame);
cv::Mat resized;
if (std::fabs(mZoom - 1.) > 0.001f)
{
cv::resize(frame, resized, cv::Size(), mZoom, mZoom);
}
else
{
resized = frame;
}
cv::imshow(mainWindowName, resized);
cv::waitKey(300);
}
@ -267,6 +276,7 @@ CalibProcessor::CalibProcessor(cv::Ptr<calibrationData> data, captureParameters
mSquareSize = capParams.squareSize;
mTemplDist = capParams.templDst;
mSaveFrames = capParams.saveFrames;
mZoom = capParams.zoom;
switch(mBoardType)
{

View File

@ -51,6 +51,7 @@ protected:
float mSquareSize;
float mTemplDist;
bool mSaveFrames;
float mZoom;
bool detectAndParseChessboard(const cv::Mat& frame);
bool detectAndParseChAruco(const cv::Mat& frame);

View File

@ -41,6 +41,7 @@ const std::string keys =
"{d | 0.8 | Min delay between captures}"
"{pf | defaultConfig.xml| Advanced application parameters}"
"{save_frames | false | Save frames that contribute to final calibration}"
"{zoom | 1 | Zoom factor applied to the image}"
"{help | | Print help}";
bool calib::showOverlayMessage(const std::string& message)

View File

@ -90,6 +90,7 @@ bool calib::parametersController::loadFromParser(cv::CommandLineParser &parser)
mCapParams.squareSize = parser.get<float>("sz");
mCapParams.templDst = parser.get<float>("dst");
mCapParams.saveFrames = parser.has("save_frames");
mCapParams.zoom = parser.get<float>("zoom");
if(!checkAssertion(mCapParams.squareSize > 0, "Distance between corners or circles must be positive"))
return false;