小编Mik*_*ael的帖子

快速(呃)匹配功能到数据库的方式

我正在开发一个项目,我在图像中有一个特征描述为一组X和Y坐标(每个特征5-10个点),这个特征对于这个特征是独一无二的.我还有一个包含数千个功能的数据库,每个功能都有相同类型的描述符.结果如下:

myFeature: (x1,y1), (x2,y2), (x3,y3)...

myDatabase: Feature1: (x1,y1), (x2,y2), (x3,y3)...
            Feature2: (x1,y1), (x2,y2), (x3,y3)...
            Feature3: (x1,y1), (x2,y2), (x3,y3)...
            ...
Run Code Online (Sandbox Code Playgroud)

我想在myDatabase的功能中找到myFeature的最佳匹配.

匹配这些功能的最快方法是什么?目前我正在踩着数据库中的每个功能并比较每个单独的点:

bestScore = 0
for each feature in myDatabase:
    score = 0
    for each point descriptor in MyFeature:
        find minimum distance from the current point to the...
          points describing the current feature in the database
        if the distance < threshold:
            there is a match to the current point in the target feature
            score += 1

    if score > bestScore:
        save …
Run Code Online (Sandbox Code Playgroud)

search matching template-matching

5
推荐指数
1
解决办法
296
查看次数

Visual C++函数突然慢了170毫秒(长4倍)

在过去的几个月里,我一直致力于Visual C++项目,从相机中获取图像并对其进行处理.到目前为止,这需要大约65毫秒来更新数据,但现在它已经突然显着增加.会发生什么:我启动我的程序,并且在前30次左右的迭代中它按预期执行,然后突然循环时间从65毫秒增加到250毫秒.

奇怪的是,在计时每个函数后,我发现引起减速的代码部分是相当基本的,并且在一个多月内没有被修改过.进入它的数据不变,每次迭代都相同,但最初小于1 ms的执行时间突然增加到170 ms,而其余代码仍然按预期执行(时间).

基本上,我一遍又一遍地调用相同的函数,因为它应该执行的前30个调用,之后它没有明显的原因减速.值得注意的是,这是执行时间的突然变化,而不是逐渐增加.

可能是什么导致了这个?代码泄漏了一些内存(~50 kb/s)但不足以保证突然4倍速度下降.如果有人有任何想法,我很乐意听到他们!

编辑:哇,那太快了!这是减速的代码(减去一些数学).我知道这是一个函数,如果你增加行数,计算时间会迅速增加.这里的关键是,使用相同的数据,这会在30次迭代后减慢.

void CameraManager::IntersectLines()
{

    // Two custom classes
    TMaths maths;
    TLine line1, line2;

    while(lines.size()>0)
    {

        // Save the current line
        line1 = lines[0];

        // Then remove it from the list
        lines.erase(lines.begin());

        CvMat* aPoint;
        for (int i = 0; i<lines.size(); i++)
        {

            line2 = lines[i];

            aPoint = cvCreateMat(1, 4, CV_32FC1);

            // Calculate the point of intersection
            maths.Intersect(line1.xyz, line2.xyz, line1.uvw, line2.uvw, aPoint);

            // Add the point to the list
            points.push_back(aPoint);
            }

        }

    }
Run Code Online (Sandbox Code Playgroud)

}

c++ memory-leaks visual-c++ slowdown

3
推荐指数
2
解决办法
612
查看次数

创建一个新对象会破坏C++中具有不同名称的旧对象

这是第一个问题!

因此,我在Visual C++ 2008中遇到了一些指针问题.我正在编写一个程序,它将控制六个摄像头并对它们进行一些处理,以便清理我创建了一个Camera Manager类.该类处理将在所有摄像机上执行的所有操作.下面是一个Camera类,它与每个单独的相机驱动程序进行交互并进行一些基本的图像处理.

现在,我们的想法是,当管理器初始化时,它会创建两个摄像头并将它们添加到矢量中,以便我以后可以访问它们.这里的问题是,当我创建第二台摄像机(camera2)时,出于某种原因调用第一台摄像机的析构函数,然后断开摄像机的连接.

通常情况下,我认为问题出在Camera类的某个地方,但在这种情况下,只要我不创建camera2对象,一切都会完美.

出了什么问题?

CameraManager.h:

#include "stdafx.h"

#include <vector>
#include "Camera.h"

class CameraManager{

    std::vector<Camera>     cameras;

public:

    CameraManager();
    ~CameraManager();

    void CaptureAll();
    void ShowAll();

};
Run Code Online (Sandbox Code Playgroud)

CameraManager.cpp:

#include "stdafx.h"

#include "CameraManager.h"


CameraManager::CameraManager()
{

    printf("Camera Manager: Initializing\n");
    [...]
    Camera *camera1 = new Camera(NodeInfo,1, -44,0,0);
    cameras.push_back(*camera1);

    // Adding the following two lines causes camera1's destructor to be called. Why?
    Camera *camera2 = new Camera(NodeInfo,0,  44,0,0);
    cameras.push_back(*camera2);

    printf("Camera Manager: Ready\n");

}
Run Code Online (Sandbox Code Playgroud)

Camera.h

#include "stdafx.h"

// OpenCV
#include <cv.h>
#include <highgui.h>

// cvBlob …
Run Code Online (Sandbox Code Playgroud)

c++ pointers object visual-c++

1
推荐指数
1
解决办法
1592
查看次数