我试图在一个相对较大的框架(4000 * 3000)中检测一个物体,然而,无论我尝试什么,探测器似乎对除了我的物体之外的所有东西都更感兴趣。我已经尝试过切换到不同的探测器和提取器,但没有任何帮助。 OpenCV生成了一系列荒谬的匹配,并且需要永远计算。
这是我的检测代码:
// get the data
m_frame_data = m_TeliDevice.getImageData();
// query info
auto info = m_TeliDevice.getImageInfo();
// query payloadsize
auto payloadSize = m_TeliDevice.getPayloadSize();
// check if the data was valid
if (!m_frame_data) return false;
// check if the payload is valid
if (3000 * 4000 > payloadSize) return false;
// initialize the Receive Frame (again) with the provided data
m_streamFrameBayer = Mat(3000, 4000, CV_8UC1, m_frame_data);
// convert to rgb
cvtColor(m_streamFrameBayer, m_frame_rgb, COLOR_BayerGR2RGB);
// create stream key points
std::vector<KeyPoint> streamKeyPoints;
// don't convert to grey for now
m_frame_greyscale = m_frame_rgb;
// create, extract and compute the descriptors for this frame
Mat descriptorFrame;
m_detector_ptr_->detect(m_frame_greyscale, streamKeyPoints);
m_compute_ptr_->compute(m_frame_greyscale, streamKeyPoints, descriptorFrame);
// allocate the Matches
std::vector<DMatch> matches, good_matches;
// match the Reference image with the current frame
m_matcher_ptr_->match(descriptorFrame, m_RefDescriptors, matches);
double max_dist = 0; double min_dist = 100;
// Quick calculation of max and min distances between keypoints
for (size_t i = 0; i < matches.size(); i++)
{
double dist = matches[i].distance;
if (dist < min_dist) min_dist = dist;
if (dist > max_dist) max_dist = dist;
}
printf("-- Max dist : %f \n", max_dist);
printf("-- Min dist : %f \n", min_dist);
// Draw only "good" matches (i.e. whose distance is less than 3*min_dist )
for (int i = 0; i < matches.size(); i++)
{
if (matches[i].distance < 3 * min_dist)
{
good_matches.push_back(matches[i]);
}
}
PIXL_PRINT_DEBUG(pixl::io::info) << "min dist " << min_dist << std::endl;
PIXL_PRINT_DEBUG(pixl::io::info) << "max dist " << max_dist << std::endl;
PIXL_PRINT_DEBUG(pixl::io::info) << "good-matches: " << good_matches.size() << std::endl;
// check if any of the matches are considered good
if(!good_matches.empty()) {
// draw the matches
drawMatches(m_frame_greyscale, streamKeyPoints, m_RefImg, m_refKeyPoints, good_matches, m_img_matches);
// convert and copy into display frame
cvtColor(m_img_matches, m_frame_rgba, COLOR_RGB2RGBA);
PIXL_PRINT_DEBUG(pixl::io::debug) << "Output Matrix Size: "<< m_img_matches.size() << std::endl;
} else {
// draw the frame & nothing else
cvtColor(m_frame_greyscale, m_frame_rgba, COLOR_RGB2RGBA);
}
// flip color
cvtColor(m_frame_rgba, m_frame_rgba, COLOR_BGRA2RGBA);
// bootstrap the OGL window
m_img.create(m_frame_rgba.cols, m_frame_rgba.rows, m_frame_rgba.ptr());
m_texture.loadFromImage(m_img);
m_sprite.setTexture(m_texture);
m_sprite.setScale({ 0.2f,0.2f });
// Extract (almost) native GL Window
auto& native = m_WindowPointer->get();
// draw the sprite in the window
native.draw(m_sprite);
//Mat H = cv::findHomography(m_refKeyPoints, streamKeyPoints);
//if (H.empty()) std::cout << "Cannot find Homography" << std::endl;
// clean up opencv's mess
good_matches.clear();
matches.clear();
m_matcher_ptr_->clear();
m_detector_ptr_->clear();
return true;
参考图像像这样预先检测到(但只有一次):
m_RefImg = imread(str.c_str(), IMREAD_COLOR);
m_detector_ptr_->detect(m_RefImg, m_refKeyPoints);
m_compute_ptr_->compute(m_RefImg, m_refKeyPoints, m_RefDescriptors);
return true;
我想添加一些图片作为参考,但它们太大了(~35MB),我不知道如何添加这些,因为最大允许的大小是2MB。