我一直致力于将自组织地图功能集成到OpenCV中。
我希望有Mat文件/对象结构,但我不希望每个“像素”或元素都是rgb值,而是希望它是一个节点对象。我有以下玩具/测试代码:
的main.cpp
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <opencv2/core/core.hpp>
#include <iostream>
#include <stdio.h>
#include <string>
#include "Node.h"
using namespace std;
using namespace cv;
int main( int, char** argv )
{
Mat myMat;
myMat = Mat_<Node*>(5, 5);
myMat.at<Node>(0,0) = new Node(); //<----- THIS IS WRONG WAY TO DO IT
return 0;
}
Node.hpp
#ifndef SRC_NODE_H_
#define SRC_NODE_H_
#include <string>
class Node {
public:
static int counter;
std::string nodeString;
int nodeInt;
Node();
virtual ~Node();
};
#endif /* SRC_NODE_H_ */
Node.cpp
#include "Node.h"
#include <iostream>
int Node::counter = 0;
Node::Node() {
nodeString = "myNodeString";
nodeInt = counter;
counter++;
std::cout << "Node Constructor Count: " << nodeInt << std::endl;
}
Node::~Node() {
}
我现在正在尝试获取每个节点对象的正确实例。我是否正确地相信我可以使用Mat_来制作带有Node对象的Mat用于“像素”值?如果我错了,还有另一种方法可以解决这个问题。我之前使用Node ***制作了一个2d数组,其中每个元素都是指向节点的指针。哦,我也不知道SOM的大小,直到运行时。
编辑:
如果我使用以下内容编译并运行,但只有Node myNode
实际上调用了节点的构造函数。其他两个似乎只能分配空间但不实例化对象。
Mat_<Node> myMat;
myMat.create(2, 2);
Node myNode;
Mat M = Mat_<Node>(3,3);