Skip to content

Commit

Permalink
Make aruco dependency optional for interactive calibration app
Browse files Browse the repository at this point in the history
  • Loading branch information
sovrasov committed Mar 22, 2017
1 parent 8abd163 commit a56bd1f
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 14 deletions.
5 changes: 4 additions & 1 deletion apps/interactive-calibration/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
set(OPENCV_INTERACTIVECALIBRATION_DEPS opencv_core opencv_imgproc opencv_features2d opencv_aruco opencv_highgui opencv_calib3d opencv_videoio)
set(OPENCV_INTERACTIVECALIBRATION_DEPS opencv_core opencv_imgproc opencv_features2d opencv_highgui opencv_calib3d opencv_videoio)
if(${BUILD_opencv_aruco})
list(APPEND OPENCV_INTERACTIVECALIBRATION_DEPS opencv_aruco)
endif()
ocv_check_dependencies(${OPENCV_INTERACTIVECALIBRATION_DEPS})

if(NOT OCV_DEPENDENCIES_FOUND)
Expand Down
12 changes: 9 additions & 3 deletions apps/interactive-calibration/frameProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#include <opencv2/calib3d.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/aruco/charuco.hpp>
#include <opencv2/highgui.hpp>

#include <vector>
Expand Down Expand Up @@ -75,6 +74,7 @@ bool CalibProcessor::detectAndParseChessboard(const cv::Mat &frame)

bool CalibProcessor::detectAndParseChAruco(const cv::Mat &frame)
{
#ifdef HAVE_OPENCV_ARUCO
cv::Ptr<cv::aruco::Board> board = mCharucoBoard.staticCast<cv::aruco::Board>();

std::vector<std::vector<cv::Point2f> > corners, rejected;
Expand All @@ -95,14 +95,16 @@ bool CalibProcessor::detectAndParseChAruco(const cv::Mat &frame)
}
centerX /= currentCharucoCorners.size[0];
centerY /= currentCharucoCorners.size[0];
//cv::circle(frame, cv::Point2f(centerX, centerY), 10, cv::Scalar(0, 255, 0), 10);

mTemplateLocations.insert(mTemplateLocations.begin(), cv::Point2f(centerX, centerY));
cv::aruco::drawDetectedCornersCharuco(frame, currentCharucoCorners, currentCharucoIds);
mCurrentCharucoCorners = currentCharucoCorners;
mCurrentCharucoIds = currentCharucoIds;
return true;
}

#else
(void)frame;
#endif
return false;
}

Expand Down Expand Up @@ -231,6 +233,7 @@ bool CalibProcessor::checkLastFrame()
}
}
else {
#ifdef HAVE_OPENCV_ARUCO
cv::Mat r, t, angles;
std::vector<cv::Point3f> allObjPoints;
allObjPoints.reserve(mCurrentCharucoIds.total());
Expand All @@ -248,6 +251,7 @@ bool CalibProcessor::checkLastFrame()
mCalibData->allCharucoCorners.pop_back();
mCalibData->allCharucoIds.pop_back();
}
#endif
}
return isFrameBad;
}
Expand All @@ -266,10 +270,12 @@ CalibProcessor::CalibProcessor(cv::Ptr<calibrationData> data, captureParameters
switch(mBoardType)
{
case chAruco:
#ifdef HAVE_OPENCV_ARUCO
mArucoDictionary = cv::aruco::getPredefinedDictionary(
cv::aruco::PREDEFINED_DICTIONARY_NAME(capParams.charucoDictName));
mCharucoBoard = cv::aruco::CharucoBoard::create(mBoardSize.width, mBoardSize.height, capParams.charucoSquareLenght,
capParams.charucoMarkerSize, mArucoDictionary);
#endif
break;
case AcirclesGrid:
mBlobDetectorPtr = cv::SimpleBlobDetector::create();
Expand Down
6 changes: 5 additions & 1 deletion apps/interactive-calibration/frameProcessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
#define FRAME_PROCESSOR_HPP

#include <opencv2/core.hpp>
#include <opencv2/aruco/charuco.hpp>
#include <opencv2/calib3d.hpp>
#ifdef HAVE_OPENCV_ARUCO
#include <opencv2/aruco/charuco.hpp>
#endif

#include "calibCommon.hpp"
#include "calibController.hpp"
Expand Down Expand Up @@ -37,8 +39,10 @@ class CalibProcessor : public FrameProcessor
cv::Mat mCurrentCharucoIds;

cv::Ptr<cv::SimpleBlobDetector> mBlobDetectorPtr;
#ifdef HAVE_OPENCV_ARUCO
cv::Ptr<cv::aruco::Dictionary> mArucoDictionary;
cv::Ptr<cv::aruco::CharucoBoard> mCharucoBoard;
#endif

int mNeededFramesNum;
unsigned mDelayBetweenCaptures;
Expand Down
24 changes: 15 additions & 9 deletions apps/interactive-calibration/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@

#include <opencv2/core.hpp>
#include <opencv2/calib3d.hpp>
#include <opencv2/aruco/charuco.hpp>
#include <opencv2/cvconfig.h>
#include <opencv2/highgui.hpp>

#ifdef HAVE_OPENCV_ARUCO
#include <opencv2/aruco/charuco.hpp>
#endif

#include <string>
#include <vector>
#include <stdexcept>
Expand Down Expand Up @@ -50,31 +53,27 @@ bool calib::showOverlayMessage(const std::string& message)
#endif
}

static void deleteButton(int state, void* data)
static void deleteButton(int, void* data)
{
state++; //to avoid gcc warnings
(static_cast<cv::Ptr<calibDataController>*>(data))->get()->deleteLastFrame();
calib::showOverlayMessage("Last frame deleted");
}

static void deleteAllButton(int state, void* data)
static void deleteAllButton(int, void* data)
{
state++;
(static_cast<cv::Ptr<calibDataController>*>(data))->get()->deleteAllData();
calib::showOverlayMessage("All frames deleted");
}

static void saveCurrentParamsButton(int state, void* data)
static void saveCurrentParamsButton(int, void* data)
{
state++;
if((static_cast<cv::Ptr<calibDataController>*>(data))->get()->saveCurrentCameraParameters())
calib::showOverlayMessage("Calibration parameters saved");
}

#ifdef HAVE_QT
static void switchVisualizationModeButton(int state, void* data)
static void switchVisualizationModeButton(int, void* data)
{
state++;
ShowProcessor* processor = static_cast<ShowProcessor*>(((cv::Ptr<FrameProcessor>*)data)->get());
processor->switchVisualizationMode();
}
Expand Down Expand Up @@ -103,6 +102,11 @@ int main(int argc, char** argv)

captureParameters capParams = paramsController.getCaptureParameters();
internalParameters intParams = paramsController.getInternalParameters();
#ifndef HAVE_OPENCV_ARUCO
if(capParams.board == chAruco)
CV_Error(cv::Error::StsNotImplemented, "Aruco module is disabled in current build configuration."
" Consider usage of another calibration pattern\n");
#endif

cv::TermCriteria solverTermCrit = cv::TermCriteria(cv::TermCriteria::COUNT+cv::TermCriteria::EPS,
intParams.solverMaxIters, intParams.solverEps);
Expand Down Expand Up @@ -172,6 +176,7 @@ int main(int argc, char** argv)
calibrationFlags, solverTermCrit);
}
else {
#ifdef HAVE_OPENCV_ARUCO
cv::Ptr<cv::aruco::Dictionary> dictionary =
cv::aruco::getPredefinedDictionary(cv::aruco::PREDEFINED_DICTIONARY_NAME(capParams.charucoDictName));
cv::Ptr<cv::aruco::CharucoBoard> charucoboard =
Expand All @@ -183,6 +188,7 @@ int main(int argc, char** argv)
globalData->cameraMatrix, globalData->distCoeffs,
cv::noArray(), cv::noArray(), globalData->stdDeviations, cv::noArray(),
globalData->perViewErrors, calibrationFlags, solverTermCrit);
#endif
}
dataController->updateUndistortMap();
dataController->printParametersToConsole(std::cout);
Expand Down

0 comments on commit a56bd1f

Please sign in to comment.