org.opencv.core.Algorithm类的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(10.2k)|赞(0)|评价(0)|浏览(137)

本文整理了Java中org.opencv.core.Algorithm类的一些代码示例,展示了Algorithm类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Algorithm类的具体详情如下:
包路径:org.opencv.core.Algorithm
类名称:Algorithm

Algorithm介绍

[英]class CV_EXPORTS_W Algorithm ``

// C++ code:

public:

Algorithm();

virtual ~Algorithm();

string name() const;

template typename ParamType.member_type get(const string& name) const;

template typename ParamType.member_type get(const char name) const;

CV_WRAP int getInt(const string& name) const;

CV_WRAP double getDouble(const string& name) const;

CV_WRAP bool getBool(const string& name) const;

CV_WRAP string getString(const string& name) const;

CV_WRAP Mat getMat(const string& name) const;

CV_WRAP vector getMatVector(const string& name) const;

CV_WRAP Ptr getAlgorithm(const string& name) const;

void set(const string& name, int value);

void set(const string& name, double value);

void set(const string& name, bool value);

void set(const string& name, const string& value);

void set(const string& name, const Mat& value);

void set(const string& name, const vector& value);

void set(const string& name, const Ptr& value);

template void set(const string& name, const Ptr& value);

CV_WRAP void setInt(const string& name, int value);

CV_WRAP void setDouble(const string& name, double value);

CV_WRAP void setBool(const string& name, bool value);

CV_WRAP void setString(const string& name, const string& value);

CV_WRAP void setMat(const string& name, const Mat& value);

CV_WRAP void setMatVector(const string& name, const vector& value);

CV_WRAP void setAlgorithm(const string& name, const Ptr& value);

template void setAlgorithm(const string& name, const Ptr& value);

void set(const char* name, int value);

void set(const char* name, double value);

void set(const char* name, bool value);

void set(const char* name, const string& value);

void set(const char* name, const Mat& value);

void set(const char* name, const vector& value);

void set(const char* name, const Ptr& value);

template void set(const char* name, const Ptr& value);

void setInt(const char* name, int value);

void setDouble(const char* name, double value);

void setBool(const char* name, bool value);

void setString(const char* name, const string& value);

void setMat(const char* name, const Mat& value);

void setMatVector(const char* name, const vector& value);

void setAlgorithm(const char* name, const Ptr& value);

template void setAlgorithm(const char* name, const Ptr& value);

CV_WRAP string paramHelp(const string& name) const;

int paramType(const char* name) const;

CV_WRAP int paramType(const string& name) const;

CV_WRAP void getParams(CV_OUT vector& names) const;

virtual void write(FileStorage& fs) const;

virtual void read(const FileNode& fn);

typedef Algorithm* (*Constructor)(void);

typedef int (Algorithm.*Getter)() const;

typedef void (Algorithm.*Setter)(int);

CV_WRAP static void getList(CV_OUT vector& algorithms);

CV_WRAP static Ptr _create(const string& name);

template static Ptr create(const string& name);

virtual AlgorithmInfo* info() const / * TODO: make it = 0;* / { return 0; }

};

This is a base class for all more or less complex algorithms in OpenCV, especially for classes of algorithms, for which there can be multiple implementations. The examples are stereo correspondence (for which there are algorithms like block matching, semi-global block matching, graph-cut etc.), background subtraction (which can be done using mixture-of-gaussians models, codebook-based algorithm etc.), optical flow (block matching, Lucas-Kanade, Horn-Schunck etc.).

The class provides the following features for all derived classes:

  • so called "virtual constructor". That is, each Algorithm derivative is registered at program start and you can get the list of registered algorithms and create instance of a particular algorithm by its name (see Algorithm.create). If you plan to add your own algorithms, it is good practice to add a unique prefix to your algorithms to distinguish them from other algorithms.
  • setting/retrieving algorithm parameters by name. If you used video capturing functionality from OpenCV highgui module, you are probably familar with cvSetCaptureProperty(), cvGetCaptureProperty(), VideoCapture.set() and VideoCapture.get(). Algorithm provides similar method where instead of integer id's you specify the parameter names as text strings. See Algorithm.set and Algorithm.get for details.
  • reading and writing parameters from/to XML or YAML files. Every Algorithm derivative can store all its parameters and then read them back. There is no need to re-implement it each time.

Here is example of SIFT use in your application via Algorithm interface: ``

// C++ code:

#include "opencv2/opencv.hpp"

#include "opencv2/nonfree/nonfree.hpp"...

initModule_nonfree(); // to load SURF/SIFT etc.

Ptr sift = Algorithm.create("Feature2D.SIFT");

FileStorage fs("sift_params.xml", FileStorage.READ);

if(fs.isOpened()) // if we have file with parameters, read them

sift->read(fs["sift_params"]);

fs.release();

else // else modify the parameters and store them; user can later edit the file to use different parameters

sift->set("contrastThreshold", 0.01f); // lower the contrast threshold, compared to the default value

WriteStructContext ws(fs, "sift_params", CV_NODE_MAP);

sift->write(fs);

Mat image = imread("myimage.png", 0), descriptors;

vector keypoints;

(*sift)(image, noArray(), keypoints, descriptors);
[中]类CV_导出算法//C++代码: 公众: 算法(); 虚拟算法(); 字符串名称()常量; 模板类型名称ParamType。成员类型get(常量字符串和名称)常量; 模板类型名称ParamType。成员类型get(const char name)const; CV_WRAP int getInt(常量字符串和名称)常量; CV_WRAP double getDouble(常量字符串和名称)常量; CV_WRAP bool getBool(常量字符串和名称)常量; CV_包装字符串getString(常量字符串和名称)常量; CV_WRAP Mat getMat(常量字符串和名称)常量; CV_包裹向量getMatVector(常量字符串和名称)常量; CV_WRAP Ptr getAlgorithm(常量字符串和名称)常量; 无效集(常量字符串和名称,int值); 无效集(常量字符串和名称,双值); 无效集(常量字符串和名称、布尔值); 无效集(常量字符串和名称、常量字符串和值); 无效集(常数字符串和名称、常数矩阵和值); 无效集(常量字符串和名称、常量向量和值); 无效集(常量字符串和名称、常量Ptr和值); 模板无效集(常量字符串和名称、常量Ptr和值); CV_WRAP void setInt(常量字符串和名称,int值); CV_WRAP void setDouble(常量字符串和名称,双精度值); CV_包装无效设置工具(常量字符串和名称,布尔值); CV_包装无效设置字符串(常量字符串和名称、常量字符串和值); CV_包装无效设置(常量字符串和名称、常量列表和值); CV_WRAP void setMatVector(常量字符串和名称、常量向量和值); CV_WRAP void setAlgorithm(常量字符串和名称、常量Ptr和值); 模板void setAlgorithm(常量字符串和名称、常量Ptr和值); 无效集(常量字符*名称,int值); 无效集(常量字符*名称,双值); 无效集(常量字符*名称,布尔值); 无效集(常量字符*名称、常量字符串和值); 无效集(常数字符*名称、常数矩阵和值); 无效集(常量字符*名称、常量向量和值); 无效集(常量字符*名称、常量Ptr和值); 模板无效集(常量字符*名称、常量Ptr和值); void setInt(常量字符*名称,int值); void setDouble(常量字符*名称,双精度值); void setBool(常量字符*名称,布尔值); 无效设置字符串(常量字符*名称、常量字符串和值); void setMat(const char*名称、const Mat和值); void setMatVector(常量字符*名称、常量向量和值); void setAlgorithm(常量字符*名称、常量Ptr和值); 模板void setAlgorithm(常量字符*名称、常量Ptr和值); CV_包装字符串参数帮助(常量字符串和名称)常量; int paramType(const char*name)const; CV_WRAP int paramType(常量字符串和名称)常量; CV_WRAP void getParams(CV_OUT vector&names)常量; 虚拟空写(文件存储&fs)常量; 虚拟无效读取(const FileNode&fn); typedef算法*(*构造函数)(无效); typedefint(算法。*Getter)()常量; typedef void(算法。*Setter)(int); CV_WRAP静态void getList(CV_OUT向量和算法); CV_包装静态Ptr_创建(常量字符串和名称); 模板静态Ptr创建(常量字符串和名称); 虚拟算法信息*info()常量/*TODO:设为=0;*/{返回0;} }; 这是OpenCV中所有或多或少复杂算法的基类,尤其是算法类,可以有多个实现。例如立体对应(有块匹配、半全局块匹配、图切割等算法)、背景减法(可以使用高斯模型、基于码本的算法等的混合实现)、光流(块匹配、Lucas Kanade、Horn-Schunck等)。 该类为所有派生类提供以下功能: *所谓的“虚拟构造函数”。也就是说,每个算法派生都是在程序启动时注册的,您可以获得已注册算法的列表,并根据其名称创建特定算法的实例(请参见`Algorithm.create`)。如果您计划添加自己的算法,最好在算法中添加一个唯一的前缀,以便将它们与其他算法区分开来。 *按名称设置/检索算法参数。如果您使用OpenCV highgui模块的视频捕获功能,您可能熟悉`cvSetCaptureProperty()`、`cvGetCaptureProperty()`、`VideoCapture.set()`和`VideoCapture.get()`。`Algorithm`提供了类似的方法,其中您将参数名称指定为文本字符串而不是整数id。有关详细信息,请参见`Algorithm.set`和`Algorithm.get`。 *从XML或YAML文件读取和写入参数。每个算法导数都可以存储其所有参数,然后将其读回。没有必要每次都重新实施它。 下面是通过算法接口在应用程序中使用SIFT的示例:
//C++代码:
#包括“opencv2/opencv.hpp”
#包括“opencv2/nonfree/nonfree.hpp”。。。
initModule_nonfree();//加载冲浪/筛选等。
Ptr sift=算法。创建(“Feature2D.SIFT”);
FileStorage fs(“sift_params.xml”,FileStorage.READ);
if(fs.isOpened())//如果我们有带参数的文件,请读取它们
筛选->读取(fs[“筛选参数]);
财政司司长。释放();
else//else修改参数并存储;用户可以稍后编辑文件以使用不同的参数
筛选->设置(“对比度阈值”,0.01f);//与默认值相比,降低对比度阈值
WriteStructContext ws(fs,“筛选参数”,CV节点映射);
筛选->写入(fs);
Mat image=imread(“myimage.png”,0),描述符;
矢量关键点;
(*筛选)(图像,noArray(),关键点,描述符);

代码示例

代码示例来源:origin: kongqw/OpenCVForAndroid

@Override
protected void finalize() throws Throwable {
  delete(nativeObj);
}

代码示例来源:origin: kongqw/OpenCVForAndroid

public  void clear()
{
  
  clear_0(nativeObj);
  
  return;
}

代码示例来源:origin: kongqw/OpenCVForAndroid

public  String getDefaultName()
{
  
  String retVal = getDefaultName_0(nativeObj);
  
  return retVal;
}

代码示例来源:origin: kongqw/OpenCVForAndroid

public  void save(String filename)
{
  
  save_0(nativeObj, filename);
  
  return;
}

代码示例来源:origin: com.sikulix/sikulixapi

public  int getInt(String name)
{
  int retVal = getInt_0(nativeObj, name);
  return retVal;
}

代码示例来源:origin: com.sikulix/sikulixapi

public  List<Mat> getMatVector(String name)
{
  List<Mat> retVal = new ArrayList<Mat>();
  Mat retValMat = new Mat(getMatVector_0(nativeObj, name));
  Converters.Mat_to_vector_Mat(retValMat, retVal);
  return retVal;
}

代码示例来源:origin: com.sikulix/sikulixapi

public  boolean getBool(String name)
{
  boolean retVal = getBool_0(nativeObj, name);
  return retVal;
}

代码示例来源:origin: ytai/IOIOPlotter

public  double getDouble(String name)
{
  double retVal = getDouble_0(nativeObj, name);
  return retVal;
}

代码示例来源:origin: DuckDeck/AndroidDemo

public  void save(String filename)
{
  
  save_0(nativeObj, filename);
  
  return;
}

代码示例来源:origin: jtsky/EasyPR_Android

public  int getInt(String name)
{
  int retVal = getInt_0(nativeObj, name);
  return retVal;
}

代码示例来源:origin: nu.pattern/opencv

public  List<Mat> getMatVector(String name)
{
  List<Mat> retVal = new ArrayList<Mat>();
  Mat retValMat = new Mat(getMatVector_0(nativeObj, name));
  Converters.Mat_to_vector_Mat(retValMat, retVal);
  return retVal;
}

代码示例来源:origin: nu.pattern/opencv

public  boolean getBool(String name)
{
  boolean retVal = getBool_0(nativeObj, name);
  return retVal;
}

代码示例来源:origin: jtsky/EasyPR_Android

public  double getDouble(String name)
{
  double retVal = getDouble_0(nativeObj, name);
  return retVal;
}

代码示例来源:origin: farkam135/GoIV

@Override
protected void finalize() throws Throwable {
  delete(nativeObj);
}

代码示例来源:origin: farkam135/GoIV

public  void clear()
{
  
  clear_0(nativeObj);
  
  return;
}

代码示例来源:origin: tz28/Chinese-number-gestures-recognition

public  String getDefaultName()
{
  
  String retVal = getDefaultName_0(nativeObj);
  
  return retVal;
}

代码示例来源:origin: tz28/Chinese-number-gestures-recognition

public  void save(String filename)
{
  
  save_0(nativeObj, filename);
  
  return;
}

代码示例来源:origin: abhn/marvel

public  int getInt(String name)
{
  int retVal = getInt_0(nativeObj, name);
  return retVal;
}

代码示例来源:origin: ytai/IOIOPlotter

public  List<Mat> getMatVector(String name)
{
  List<Mat> retVal = new ArrayList<Mat>();
  Mat retValMat = new Mat(getMatVector_0(nativeObj, name));
  Converters.Mat_to_vector_Mat(retValMat, retVal);
  return retVal;
}

代码示例来源:origin: ytai/IOIOPlotter

public  boolean getBool(String name)
{
  boolean retVal = getBool_0(nativeObj, name);
  return retVal;
}

相关文章