gpt4 book ai didi

c++ - OpenCV - 实现新描述符时的链接器错误 - 旋转不变 BRIEF

转载 作者:太空宇宙 更新时间:2023-11-03 22:58:21 24 4
gpt4 key购买 nike

<分区>

作为我对二进制描述符的研究的一部分,我正在实现 BRIEF 的旋转不变版本。基本上,我将采样点旋转了补丁的角度(由检测器给出)。

现在,我遇到了函数链接问题:

AlgorithmInfo* info() const;

我收到带有函数名称的“未解析的外部符号”。

这是我的代码:在 features2d.hpp":

class CV_EXPORTS InvariantBriefDescriptorExtractor : public DescriptorExtractor
{
public:
static const int PATCH_SIZE = 48;
static const int KERNEL_SIZE = 9;
// bytes is a length of descriptor in bytes. It can be equal 16, 32 or 64 bytes.
InvariantBriefDescriptorExtractor(int bytes = 32);

virtual void read(const FileNode&);
virtual void write(FileStorage&) const;

virtual int descriptorSize() const;
virtual int descriptorType() const;


AlgorithmInfo* info() const;

protected:
virtual void computeImpl(const Mat& image, vector<KeyPoint>& keypoints, Mat& descriptors) const;
typedef void(*PixelTestFn)(const Mat&, const vector<KeyPoint>&, const int *, Mat&);

int bytes_;
PixelTestFn test_fn_;
static int bit_pattern_64_[512 * 4];
};

和文件 BriefRI.cpp(包含实现):

#include "precomp.hpp"
#include <algorithm>
#include <vector>

#include <iostream>
#include <iomanip>

using namespace cv;

static void calculateSums(const Mat &sum, const int &count, const int *pattern, float &cos_theta, float &sin_theta, KeyPoint pt);

inline int smoothedSum(const Mat& sum, const KeyPoint& pt, int y, int x)
{
static const int HALF_KERNEL = BriefDescriptorExtractor::KERNEL_SIZE / 2;

int img_y = (int)(pt.pt.y + 0.5) + y;
int img_x = (int)(pt.pt.x + 0.5) + x;
return sum.at<int>(img_y + HALF_KERNEL + 1, img_x + HALF_KERNEL + 1)
- sum.at<int>(img_y + HALF_KERNEL + 1, img_x - HALF_KERNEL)
- sum.at<int>(img_y - HALF_KERNEL, img_x + HALF_KERNEL + 1)
+ sum.at<int>(img_y - HALF_KERNEL, img_x - HALF_KERNEL);
}

static void pixelTests16(const Mat& sum, const std::vector<KeyPoint>& keypoints, const int *pattern, Mat& descriptors)
{
for (int i = 0; i < (int)keypoints.size(); ++i)
{
uchar* desc = descriptors.ptr(i);
const KeyPoint& pt = keypoints[i];

float angle = pt.angle;
angle *= (float)(CV_PI / 180.f);
float cos_theta = cos(angle);
float sin_theta = sin(angle);
int count = 0;

for (int ix = 0; ix < 16; ix++){
for (int jx = 7; jx >= 0; jx--){

int suma, sumb;
calculateSums(sum, count, pattern,cos_theta, sin_theta, pt);
desc[ix] += (uchar)((suma< sumb) << jx);
count += 4;
}
}
}
}

static void pixelTests32(const Mat& sum, const std::vector<KeyPoint>& keypoints, const int *pattern, Mat& descriptors)
{
for (int i = 0; i < (int)keypoints.size(); ++i)
{
uchar* desc = descriptors.ptr(i);
const KeyPoint& pt = keypoints[i];

float angle = pt.angle;
angle *= (float)(CV_PI / 180.f);
float cos_theta = cos(angle);
float sin_theta = sin(angle);
int count = 0;

for (int ix = 0; ix < 32; ix++){
for (int jx = 7; jx >= 0; jx--){

int suma, sumb;
calculateSums(sum, count, pattern,cos_theta, sin_theta, pt);
desc[ix] += (uchar)((suma< sumb) << jx);
count += 4;
}
}


}
}

static void pixelTests64(const Mat& sum, const std::vector<KeyPoint>& keypoints, const int *pattern, Mat& descriptors)
{
for (int i = 0; i < (int)keypoints.size(); ++i)
{
uchar* desc = descriptors.ptr(i);
const KeyPoint& pt = keypoints[i];

float angle = pt.angle;
angle *= (float)(CV_PI / 180.f);
float cos_theta = cos(angle);
float sin_theta = sin(angle);
int count = 0;

for (int ix = 0; ix < 64; ix++){
for (int jx = 7; jx >= 0; jx--){

int suma, sumb;
calculateSums(sum, count,pattern, cos_theta, sin_theta, pt);
desc[ix] += (uchar)((suma< sumb) << jx);
count += 4;
}
}

}
}

static void calculateSums(const Mat &sum, const int &count, const int *pattern, float &cos_theta, float &sin_theta, KeyPoint pt){
int ax = pattern[count];
int ay = pattern[count + 1];

int bx = pattern[count + 2];
int by = pattern[count + 3];

int ax2 = ((float)ax)*cos_theta - ((float)ay)*sin_theta;
int ay2 = ((float)ax)*sin_theta + ((float)ay)*cos_theta;
int bx2 = ((float)bx)*cos_theta - ((float)by)*sin_theta;
int by2 = ((float)bx)*sin_theta + ((float)by)*cos_theta;

int suma = smoothedSum(sum, pt, ay, ax);
int sumb = smoothedSum(sum, pt, by, bx);
}

namespace cv
{

InvariantBriefDescriptorExtractor::InvariantBriefDescriptorExtractor(int bytes) :
bytes_(bytes), test_fn_(NULL)
{
switch (bytes)
{
case 16:
test_fn_ = pixelTests16;
break;
case 32:
test_fn_ = pixelTests32;
break;
case 64:
test_fn_ = pixelTests64;
break;
default:
CV_Error(CV_StsBadArg, "bytes must be 16, 32, or 64");
}
}

int InvariantBriefDescriptorExtractor::descriptorSize() const
{
return bytes_;
}

int InvariantBriefDescriptorExtractor::descriptorType() const
{
return CV_8UC1;
}

void InvariantBriefDescriptorExtractor::read(const FileNode& fn)
{
int dSize = fn["descriptorSize"];
switch (dSize)
{
case 16:
test_fn_ = pixelTests16;
break;
case 32:
test_fn_ = pixelTests32;
break;
case 64:
test_fn_ = pixelTests64;
break;
default:
CV_Error(CV_StsBadArg, "descriptorSize must be 16, 32, or 64");
}
bytes_ = dSize;
}

void InvariantBriefDescriptorExtractor::write(FileStorage& fs) const
{
fs << "descriptorSize" << bytes_;
}

void InvariantBriefDescriptorExtractor::computeImpl(const Mat& image, std::vector<KeyPoint>& keypoints, Mat& descriptors) const
{
// Construct integral image for fast smoothing (box filter)
Mat sum;

Mat grayImage = image;
if (image.type() != CV_8U) cvtColor(image, grayImage, CV_BGR2GRAY);

///TODO allow the user to pass in a precomputed integral image
//if(image.type() == CV_32S)
// sum = image;
//else

integral(grayImage, sum, CV_32S);

//Remove keypoints very close to the border
KeyPointsFilter::runByImageBorder(keypoints, image.size(), PATCH_SIZE / 2 + KERNEL_SIZE / 2);

descriptors = Mat::zeros((int)keypoints.size(), bytes_, CV_8U);
test_fn_(sum, keypoints, bit_pattern_64_,descriptors);
}


int InvariantBriefDescriptorExtractor:: bit_pattern_64_[512 * 4] =
{ -1, -2, -1, 7
, -1, -14, 3, -3
, -2, 1, 2, 11
, 6, 1, -7, -10
, 2, 13, 0, -1
, 5, -14, -3, 5
, 8, -2, 4, 2
, 8, -11, 5, -15
(LONG LIST)

提前致谢!

吉尔

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com