Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#Macbeth Chart detection Bugs# #3599

Open
wants to merge 2 commits into
base: 4.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
57 changes: 37 additions & 20 deletions modules/mcc/src/checker_detector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include "wiener_filter.hpp"
#include "checker_model.hpp"
#include "debug.hpp"

#include <iostream>
namespace cv
{
namespace mcc
Expand Down Expand Up @@ -232,11 +232,17 @@ bool CCheckerDetectorImpl::
}
showAndSave("checker_analysis", image_checker, pathOut);
#endif
for (Ptr<CChecker> checker : checkers)

for (Ptr<CChecker>& checker : checkers)
{
for (cv::Point2f &corner : checker->getBox())
//std::cout << "===1,get-checkers-box= " << checker->getBox() << std::endl;
std::vector<cv::Point2f> restore_box;
for (cv::Point2f& corner : checker->getBox()) {
corner += static_cast<cv::Point2f>(region.tl());

restore_box.emplace_back(corner);
}
checker->setBox(restore_box);
//std::cout << "===1,get-checkers-box= " << checker->getBox() << std::endl;
mtx.lock(); // push_back is not thread safe
m_checkers.push_back(checker);
mtx.unlock();
Expand All @@ -260,33 +266,29 @@ bool CCheckerDetectorImpl::
const int nc /*= 1*/, bool useNet /*=false*/, const Ptr<DetectorParameters> &params)
{
m_checkers.clear();

if (this->net.empty() || !useNet)
{
return _no_net_process(image, chartType, nc, params, regionsOfInterest);
}
this->net_used = true;

cv::Mat img = image.getMat();

cv::Mat img_rgb_org, img_ycbcr_org;
std::vector<cv::Mat> rgb_planes(3), ycbcr_planes(3);
for (const cv::Rect &region : regionsOfInterest)
{
cv::Mat croppedImage = img(region);

// Convert to RGB and YCbCr space
cv::cvtColor(img, img_rgb_org, COLOR_BGR2RGB);
cv::cvtColor(img, img_ycbcr_org, COLOR_BGR2YCrCb);
cv::Mat img_rgb_org, img_ycbcr_org;

// Get chanels
split(img_rgb_org, rgb_planes);
split(img_ycbcr_org, ycbcr_planes);
// Convert to RGB and YCbCr space
cv::cvtColor(croppedImage, img_rgb_org, COLOR_BGR2RGB);
cv::cvtColor(croppedImage, img_ycbcr_org, COLOR_BGR2YCrCb);

for (const cv::Rect &region : regionsOfInterest)
{
//-------------------------------------------------------------------
// Run the model to find good regions
//-------------------------------------------------------------------

cv::Mat croppedImage = img(region);

int rows = croppedImage.size[0];
int cols = croppedImage.size[1];
Expand Down Expand Up @@ -436,26 +438,41 @@ bool CCheckerDetectorImpl::
}
showAndSave("checker_recognition", image_box, pathOut);
#endif

cv::Mat img_rgb_org_roi = img_rgb_org(innerRegion);
cv::Mat img_ycbcr_org_roi = img_ycbcr_org(innerRegion);
// Get chanels
std::vector<cv::Mat> rgb_planes(3), ycbcr_planes(3);
split(img_rgb_org_roi, rgb_planes);
split(img_ycbcr_org_roi, ycbcr_planes);

//-------------------------------------------------------------------
// checker color analysis
//-------------------------------------------------------------------
std::vector<Ptr<CChecker>> checkers;
checkerAnalysis(img_rgb_f, chartType, nc, colorCharts, checkers, asp, params,
img_rgb_org, img_ycbcr_org, rgb_planes, ycbcr_planes);
img_rgb_org_roi, img_ycbcr_org_roi, rgb_planes, ycbcr_planes);
#ifdef MCC_DEBUG
cv::Mat image_checker;
innerCroppedImage.copyTo(image_checker);

for (size_t ck = 0; ck < checkers.size(); ck++)
{
Ptr<CCheckerDraw> cdraw = CCheckerDraw::create((checkers[ck]));
cdraw->draw(image_checker);
}
showAndSave("checker_analysis", image_checker, pathOut);
#endif
for (Ptr<CChecker> checker : checkers)
for (Ptr<CChecker>& checker : checkers)
{
for (cv::Point2f &corner : checker->getBox())
//std::cout<<"===1,get-checkers-box= "<<checker->getBox()<<std::endl;
std::vector<cv::Point2f> restore_box;
for (cv::Point2f& corner : checker->getBox()) {
corner += static_cast<cv::Point2f>(region.tl() + innerRegion.tl());
restore_box.emplace_back(corner);
}
checker->setBox(restore_box);
//std::cout<<"===2,get-checkers-box= "<<checker->getBox()<<std::endl;
mtx.lock(); // push_back is not thread safe
m_checkers.push_back(checker);
mtx.unlock();
Expand Down