Commit 6c7a3b1b authored by 姜天宇's avatar 姜天宇

feat(v1.0.2): 集成索引库算法(索引库版本较老,可能存在最后一条索引删除不掉的BUG)

parent 2b780db7
......@@ -53,7 +53,7 @@ android {
dataBinding true
buildConfig true
}
ndkVersion '25.1.8937393'
ndkVersion '23.1.7779620'
}
dependencies {
......
......@@ -211,7 +211,9 @@ public class EnglishAndNumberKeyboard extends ConstraintLayout {
@BindingAdapter("keywords")
public static void setKeywords(EnglishAndNumberKeyboard view, String keywords){
view.setKeywords(keywords);
if (view != null) {
view.setKeywords(keywords);
}
}
@InverseBindingAdapter(attribute = "keywords", event = "keywordsAttrChanged")
......
......@@ -3,6 +3,8 @@ package com.wmdigit.common.view.spinner;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListPopupWindow;
import android.widget.PopupWindow;
......@@ -11,6 +13,9 @@ import android.widget.Spinner;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.databinding.BindingAdapter;
import androidx.databinding.InverseBindingAdapter;
import androidx.databinding.InverseBindingListener;
import com.elvishew.xlog.XLog;
import com.wmdigit.common.R;
......@@ -26,6 +31,8 @@ public class MySpinner extends ConstraintLayout {
private Spinner spinner;
private static InverseBindingListener inverseBindingListener;
public MySpinner(@NonNull Context context) {
super(context);
LayoutInflater.from(context).inflate(R.layout.layout_dropdown_spinner, this, true);
......@@ -52,6 +59,19 @@ public class MySpinner extends ConstraintLayout {
private void initView() {
spinner = findViewById(R.id.spinner);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if (inverseBindingListener != null){
inverseBindingListener.onChange();
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
try {
Field listPopupField = Spinner.class.getDeclaredField("mPopup");
listPopupField.setAccessible(true);
......@@ -71,6 +91,14 @@ public class MySpinner extends ConstraintLayout {
}
public void setSelectedIndex(int index){
spinner.setSelection(index);
}
public int getSelectedIndex(){
return spinner.getSelectedItemPosition();
}
public void setSpinnerEntries(List<String> value){
spinner.setAdapter(new ArrayAdapter(getContext(), R.layout.spinner_item, value));
}
......@@ -79,6 +107,29 @@ public class MySpinner extends ConstraintLayout {
spinner.setAdapter(ArrayAdapter.createFromResource(getContext(), resId, R.layout.spinner_item));
}
// public static void
@BindingAdapter("selectedItem")
public static void setSelectedItem(MySpinner view, Integer selectedIndex){
if (selectedIndex != null){
view.setSelectedIndex(selectedIndex);
}
}
@InverseBindingAdapter(attribute = "selectedItem", event = "selectedItemAttrChanged")
public int getSelectedItem(MySpinner view){
return view.getSelectedIndex();
}
@BindingAdapter(value = "selectedItemAttrChanged")
public static void setSelectedItemChangedListener(MySpinner view, InverseBindingListener listener){
if (listener != null){
inverseBindingListener = listener;
}
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
inverseBindingListener = null;
spinner.setOnItemSelectedListener(null);
}
}
......@@ -17,7 +17,14 @@ android {
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags ""
// cppFlags ""
arguments "-DANDROID_TOOLCHAIN=clang"
arguments "-DCMAKE_BUILD_TYPE=Release"
cppFlags "-std=c++11", "-frtti", "-fexceptions"
//sample cpp flag parameters
// cppFlags "-std=c++14 -Ofast -Rpass-analysis=loop-vectorize -fsave-optimization-record -fdiagnostics-show-hotness"
//set -DANDROID_STL to c++_shared
// arguments "-DANDROID_STL=c++_shared"
}
}
}
......@@ -34,6 +41,7 @@ android {
targetCompatibility JavaVersion.VERSION_1_8
}
sourceSets {
main {
jniLibs.srcDirs = ['src/main/jniLibs']
......
cmake_minimum_required(VERSION 3.18.1)
add_definitions(-w)
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -s -O3 -DSkip_f2c_Undefs -DNO_LONG_LONG -DNO_BLAS_WRAP")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -s -O3 -DSkip_f2c_Undefs -DNO_LONG_LONG -DNO_BLAS_WRAP")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fopenmp -static-openmp")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp -static-openmp")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2 -fvisibility=hidden -fomit-frame-pointer -fstrict-aliasing -ffunction-sections -fdata-sections -ffast-math -Wl,--gc-sections")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -fvisibility=hidden -fvisibility-inlines-hidden -fomit-frame-pointer -fstrict-aliasing -ffunction-sections -fdata-sections -ffast-math -Wl,--gc-sections")
# Declares and names the project.
project("core")
......@@ -30,6 +40,22 @@ set_target_properties(
${CMAKE_SOURCE_DIR}/../jniLibs/${ANDROID_ABI}/libc++_shared.so
)
# todo 测试用
#add_library(retri SHARED IMPORTED)
#set_target_properties(
# retri
# PROPERTIES IMPORTED_LOCATION
# ${CMAKE_SOURCE_DIR}/../jniLibs/${ANDROID_ABI}/libretri.a
#)
# hnsw索引库
add_library(hnsw SHARED IMPORTED)
set_target_properties(
hnsw
PROPERTIES IMPORTED_LOCATION
${CMAKE_SOURCE_DIR}/../jniLibs/${ANDROID_ABI}/libret.so
)
# 分类、特征提取库
add_library(clsretri SHARED IMPORTED)
set_target_properties(
......@@ -193,4 +219,25 @@ target_link_libraries(
opencv
image_tools
${log-lib}
)
# hnsw索引
add_library(
features_hnsw
SHARED
features_hnsw.cpp
)
target_link_libraries(
features_hnsw
jnigraphics
android
opencv
# wmai
# retri
hnsw
c++_shared
${log-lib}
)
\ No newline at end of file
#include "include/features_hnsw.h"
/**
* 索引库初始化
*/
extern "C"
JNIEXPORT jint JNICALL
Java_com_wmdigit_core_hnsw_HnswManager_init(JNIEnv *env, jobject thiz) {
std::vector<std::pair<long, std::string>>().swap(vector);
idx = new libhnsw::Index(FEATURES_DIMENSION, FEATURES_TOTAL, mode);
LOGI("索引库初始化完成");
return 0;
}
/**
* 写入索引
*/
extern "C"
JNIEXPORT jlong JNICALL
Java_com_wmdigit_core_hnsw_HnswManager_writeSample(JNIEnv *env, jobject thiz, jlong id,
jstring code, jfloatArray feature) {
jlong result = -1;
if (idx == nullptr){
return result;
}
// jfloatArray转float*
float* array = env->GetFloatArrayElements(feature, JNI_FALSE);
int tempId = id;
// 写入索引库
int ret = idx->Addsample(array, tempId);
if (ret == 0){
LOGE("写入索引失败");
}
// 释放
env->ReleaseFloatArrayElements(feature, array, 0);
// jstring转char*
const char* productCode = env->GetStringUTFChars(code, JNI_FALSE);
// 检查索引库大小
if (idx->get_cur_element_count() >= FEATURES_TOTAL){
// 索引库已超过50000条记录,从vector中取出头部键值
long firstId = vector.begin()->first;
// 从索引库删除对应id的索引
int tempFirstId = firstId;
idx->Removesample(tempFirstId);
// 将vector头部删除
vector.erase(vector.begin());
// 记录需要删除的主键值
result = firstId;
}
// 写入vector
vector.emplace_back(tempId, productCode);
// 释放
env->ReleaseStringUTFChars(code, productCode);
return result;
}
/**
* 清空索引库
*/
extern "C"
JNIEXPORT void JNICALL
Java_com_wmdigit_core_hnsw_HnswManager_deleteAllSample(JNIEnv *env, jobject thiz) {
if (idx != nullptr){
delete idx;
idx = nullptr;
}
LOGI("索引库已清空");
}
extern "C"
/**
* 检索出最相似结果
* @param env
* @param thiz
* @param feature
* @param threshold
* @return
*/
JNIEXPORT jstring JNICALL
Java_com_wmdigit_core_hnsw_HnswManager_retrieveMostSimilarResult(JNIEnv *env, jobject thiz,
jfloatArray feature,
jfloat threshold) {
jstring productCode = nullptr;
if (idx == nullptr){
return productCode;
}
// jfloatArray转float*
float * array = env->GetFloatArrayElements(feature, JNI_FALSE);
// 在索引库中检索最接近的
std::vector<std::pair<float, int>> result = idx->Search(array, 1);
if (!result.empty()){
LOGI("%d = %f", result[0].second, result[0].first);
// 取出检索结果中的label
int label = result[0].second;
// 取出对应的特征
libhnsw::RequireSample requireSample;
idx->Selectsample(requireSample, label);
// 计算相似度
float similarity = calculateSimilar(array, requireSample.data, FEATURES_DIMENSION);
if (similarity >= threshold){
// 相似度大于设定阈值,在vector中检索出对应的code
for (auto it = vector.begin(); it != vector.end(); it++) {
if (it->first == result[0].second){
productCode = env->NewStringUTF(it->second.c_str());
break;
}
}
}
idx->freeSelectsample(&requireSample);
}
// 释放
env->ReleaseFloatArrayElements(feature, array, 0);
return productCode;
}
/**
* 计算相似度
* @param v1
* @param v2
* @param size
* @return
*/
float calculateSimilar(const float v1[], const float v2[], int size) {
// assert(v1.size() == v2.size());
double ret = 0.0, mod1 = 0.0, mod2 = 0.0;
for (int i = 0; i < size; ++i) {
ret += v1[i] * v2[i];
mod1 += v1[i] * v1[i];
mod2 += v2[i] * v2[i];
}
if (mod1 == 0 || mod2 == 0) return 0;
return (ret / sqrt(mod1) / sqrt(mod2) + 1) / 2.0;
}
\ No newline at end of file
#ifndef CATERINGDETECT_FEATURES_HNSW_H
#define CATERINGDETECT_FEATURES_HNSW_H
#include <jni.h>
#include <android/log.h>
#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/imgproc.hpp>
#include "libretri.h"
#include "libhnsw.h"
#define LOG_TAG "JNI_HNSW"
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG, __VA_ARGS__)
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG, __VA_ARGS__)
#define LOGW(...) __android_log_print(ANDROID_LOG_WARN,LOG_TAG, __VA_ARGS__)
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG, __VA_ARGS__)
#define LOGF(...) __android_log_print(ANDROID_LOG_FATAL,LOG_TAG, __VA_ARGS__)
// 特征维度
#define FEATURES_DIMENSION 128
// 特征总数
#define FEATURES_TOTAL 50000
// 索引
libhnsw::Index *idx = nullptr;
// 算法类型
libhnsw::MODE mode = libhnsw::BRUTE_FORCE_KNN_CF;
// 计算方式
libhnsw::SPACE_TYPE st = libhnsw::L2_DISTANCE;
// vector, 存放索引库label和商品编码的对应关系
// first->索引库中Label,实际为特征向量在数据库中的自增ID
// 注意索引库中该值为int,而数据库中该值为long
// second->商品code
std::vector<std::pair<long, std::string>> vector;
/**
* 计算相似度
* @param v1
* @param v2
* @param size
* @return
*/
float calculateSimilar(const float v1[], const float v2[], int size);
#endif
\ No newline at end of file
#pragma once
#include <string>
#include <vector>
#include "opencv2/opencv.hpp"
namespace libhnsw {
enum MODE
{
BRUTE_FORCE_KNN = 0,
BRUTE_FORCE_KNN_CF = 1,
HNSW_FORCE_KNN = 2,
HNSW_FORCE_KNN_CF = 3,
MNN_MATMUL_CF = 4,
OPENCV_MATMUL_CF = 5
};
enum SPACE_TYPE
{
INNER_PRODUCT=0,
L1_DISTANCE=1,
L2_DISTANCE=2,
};
struct RequireSample //查询向量结构体
{
float* data=NULL;
int d; // 向量维度,如果是0表示未查询到
};
class Index
{
public:
// 构造函数1:初始化
Index(int d, int n, MODE md,SPACE_TYPE st=L2_DISTANCE,
size_t M = 16, size_t ef_construction = 200, size_t random_seed = 100);
~Index();
// 构造函数2:初始化load index(废弃20211224)
//Index(const std::string index_path,int d, int n, MODE md,SPACE_TYPE st=L2_DISTANCE);
// 加载Index:成功:1;失败:0(新增20211224)
int loadIndex(const std::string& location);
// 增加一个样本
int Addsample(float *sample, int label);
// 删除一个样本
int Removesample(int label);
// 检索一个样本
std::vector<std::pair<float, int>> Search(float* sample, int k);
// 查询一个样本(仅支持BRUTE模式)
int Selectsample(RequireSample& sample, int label);
// 释放一个查询样本
int freeSelectsample(RequireSample* sample);
// 保存index
void saveIndex(const std::string &location);
// 获取index的最大容量
int get_max_elements();
// 获取index的当前容量
int get_cur_element_count();
// 该值等于fea_dim_*sizeof(float)
int get_data_size();
private:
int fea_dim_; // 特征维度
int num_; // 最大容量
MODE md_; // 算法类型
SPACE_TYPE st_; // 计算方式
};
}
\ No newline at end of file
#pragma once
#ifndef _RETRI_LIB_H_
#define _RETRI_LIB_H_
#include <vector>
#include "opencv2/opencv.hpp"
#define RETRI_FEAT_DIM 128
#define RETRI_INPUT_WIDTH 224
#define RETRI_INPUT_HEIGHT 224
#define RETRI_ALL_OK 0x00000000 //
#define RETRI_OUTPUT_SHAPE_ERROR 0x10080001 // 输出的维度有错误
#define RETRI_INPUT_IMAGE_EMPTY 0x10080002 // 输入的图像为空
#define RETRI_HANDLE_NULL 0x10080003 // 输入的句柄为空
#define RETRI_OUTPUT_NULL 0x10080004 // 输入的返回结构体为空
#define RETRI_SESSION_NULL 0x10080005 //
#define RETRI_INIT_MODEL_PATH_NOT_EXIST 0x10080006 // 输入的模型路径不存在
#define RETRI_CREATE_NET_FAILED 0x10080007 // 创建的模型失败
#define RETRI_GET_NET_INPUT_FAILED 0x10080008 // 获取输入tensor失败
#define RETRI_GET_NET_OUTPUT_CLS_FAILED 0x10080009 // 获取输出tensor失败
#define RETRI_GET_NET_OUTPUT_FEAT_FAILED 0x1008000A // 获取输出tensor失败
#define RETRI_GET_NET_SESSION_FAILED 0x1008000B // 获取输出session失败
#define RETRI_FREE_SESSION_FAILED 0x1008000C // 释放session失败
#define RETRI_INPUT_SIZE_ERROR 0x1008000D // 模型中获取的输入形状与设置的不一致
#define RETRI_OUTPUT_CLS_SIZE_ERROR 0x10080010 // 模型中获取的输出维度与设置的不一致
#define RETRI_OUTPUT_FEA_SIZE_ERROR 0x10080011 // 模型中获取的输出维度与设置的不一致
#define RETRI_GETINFO_NAME_ILLEGAL 0x10080012 // 获取当前信息的Name非法
#define RETRI_INIT_CACHE_DIR_CREATE_FAILED 0x10080013 // 创建cache dir失败
typedef struct _RETRI_REGISTER_RES_
{
int success_flag; // 注册成功标志位:0-失败 1-成功
}RETRI_REGISTER_RES;
// 定义算法的识别设备
typedef enum _RETRI_DEVICE_
{
RETRI_CPU = 0x0000, // CPU
RETRI_GPU = 0x0001, // GPU
}RETRI_DEVICE;
typedef struct _RETRI_INIT_INFO_
{
int precision_level = 0; // Precision_Normal = 0, Precision_High=1, Precision_Low=2
int mem_level = 0; // Memory_Normal = 0, Memory_High=1, Memory_Low=2
int pow_level = 0; // Power_Normal = 0, Power_High=1, Power_Low=2
const char* model_path = nullptr;
const char* cache_dir = nullptr;
RETRI_DEVICE device_type;
}RETRI_INIT_INFO;
typedef struct _RETRI_INPUT_
{
cv::Mat img;
}RETRI_INPUT;
typedef struct _RETRI_OUTPUT_
{
float feat[RETRI_FEAT_DIM];
}RETRI_OUTPUT;
/***************************************************************************************************
* 功 能: 初始化
* 参 数:
* const char* model_path - I 模型路径或者cache路径文件夹路径
* 1. 内部会判断是文件夹还是文件
* 2. 如果是文件夹,则会在该文件夹下产生cache
* 3. 如果设置为NULL,则cache产生在当前exe同级目录下
* RETRI_DEVICE device_name - I 设备类型
* void** retri_handle - O 句柄
* 返回值: 错误码
***************************************************************************************************/
int RETRI_Init(RETRI_INIT_INFO init_info,
void** retri_handle);
/***************************************************************************************************
* 功 能: 识别
* 参 数:
* RETRI_INPUT in_img - I 输入图片
* RETRI_OUTPUT* retri_output - O 返回识别结果
* void* handle - I 句柄
* 返回值: 错误码
***************************************************************************************************/
int RETRI_Process(RETRI_INPUT in_img, RETRI_OUTPUT* retri_output, void* handle);
/***************************************************************************************************
* 功 能: 获取信息
* 参 数:
* void* handle - I 句柄
* char* name - I 信息名字
* 目前支持:running_device
* void* info - O 信息
* 返回值: 错误码
***************************************************************************************************/
int RETRI_GetInfo(void* handle,const char* name, void* info);
/***************************************************************************************************
* 功 能: 释放句柄
* 参 数:
* void** handle - I 句柄
* 返回值: 错误码
***************************************************************************************************/
int RETRI_Release(void** handle);
#endif
\ No newline at end of file
......@@ -1119,7 +1119,7 @@ CV_EXPORTS_W double stereoCalibrate( InputArrayOfArrays objectPoints,
camera.
@param P2 Output 3x4 projection matrix in the new (rectified) coordinate systems for the second
camera.
@param Q Output \f$4 \times 4\f$ disparity-to-mDepthParam mapping matrix (see reprojectImageTo3D ).
@param Q Output \f$4 \times 4\f$ disparity-to-depth mapping matrix (see reprojectImageTo3D ).
@param flags Operation flags that may be zero or CALIB_ZERO_DISPARITY . If the flag is set,
the function makes the principal points of each camera have the same pixel coordinates in the
rectified views. And if the flag is not set, the function may still shift the images in the
......@@ -1463,7 +1463,7 @@ matrix E. Only these inliers will be used to recover pose. In the output mask on
which pass the cheirality check.
This function decomposes an essential matrix using decomposeEssentialMat and then verifies possible
pose hypotheses by doing cheirality check. The cheirality check basically means that the
triangulated 3D points should have positive mDepthParam. Some details can be found in @cite Nister03 .
triangulated 3D points should have positive depth. Some details can be found in @cite Nister03 .
This function can be used to process output E and mask from findEssentialMat. In this scenario,
points1 and points2 are the same input for findEssentialMat. :
......@@ -1651,8 +1651,8 @@ map.
points where the disparity was not computed). If handleMissingValues=true, then pixels with the
minimal disparity that corresponds to the outliers (see StereoMatcher::compute ) are transformed
to 3D points with a very large Z value (currently set to 10000).
@param ddepth The optional output array mDepthParam. If it is -1, the output image will have CV_32F
mDepthParam. ddepth can also be set to CV_16S, CV_32S or CV_32F.
@param ddepth The optional output array depth. If it is -1, the output image will have CV_32F
depth. ddepth can also be set to CV_16S, CV_32S or CV_32F.
The function transforms a single-channel disparity map to a 3-channel image representing a 3D
surface. That is, for each pixel (x,y) andthe corresponding disparity d=disparity(x,y) , it
......@@ -1797,7 +1797,7 @@ CV_EXPORTS_W cv::Mat estimateAffinePartial2D(InputArray from, InputArray to, Out
This function extracts relative camera motion between two views observing a planar object from the
homography H induced by the plane. The intrinsic camera matrix K must also be provided. The function
may return up to four mathematical solution sets. At least two of the solutions may further be
invalidated if point correspondences are available by applying positive mDepthParam constraint (all points
invalidated if point correspondences are available by applying positive depth constraint (all points
must be in front of the camera). The decomposition method is described in detail in @cite Malis .
*/
CV_EXPORTS_W int decomposeHomographyMat(InputArray H,
......@@ -2180,7 +2180,7 @@ optimization. It stays at the center or at a different location specified when C
camera.
@param P2 Output 3x4 projection matrix in the new (rectified) coordinate systems for the second
camera.
@param Q Output \f$4 \times 4\f$ disparity-to-mDepthParam mapping matrix (see reprojectImageTo3D ).
@param Q Output \f$4 \times 4\f$ disparity-to-depth mapping matrix (see reprojectImageTo3D ).
@param flags Operation flags that may be zero or CALIB_ZERO_DISPARITY . If the flag is set,
the function makes the principal points of each camera have the same pixel coordinates in the
rectified views. And if the flag is not set, the function may still shift the images in the
......
This diff is collapsed.
......@@ -156,8 +156,8 @@ namespace cv
channels = 16,
fmt = traits::SafeFmt<channel_type>::fmt + ((channels - 1) << 8)
#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED
,mDepthParam = DataType<channel_type>::mDepthParam
,type = CV_MAKETYPE(mDepthParam, channels)
,depth = DataType<channel_type>::depth
,type = CV_MAKETYPE(depth, channels)
#endif
};
......
......@@ -83,7 +83,7 @@ enum Code {
BadModelOrChSeq= -14, //!<
BadNumChannels= -15, //!< bad number of channels, for example, some functions accept only single channel matrices.
BadNumChannel1U= -16, //!<
BadDepth= -17, //!< input image mDepthParam is not supported by the function
BadDepth= -17, //!< input image depth is not supported by the function
BadAlphaChannel= -18, //!<
BadOrder= -19, //!< number of dimensions is out of range
BadOrigin= -20, //!< incorrect input origin
......
......@@ -91,7 +91,7 @@ CVAPI(void) cvFree_( void* ptr );
/** @brief Creates an image header but does not allocate the image data.
@param size Image width and height
@param depth Image mDepthParam (see cvCreateImage )
@param depth Image depth (see cvCreateImage )
@param channels Number of channels (see cvCreateImage )
*/
CVAPI(IplImage*) cvCreateImageHeader( CvSize size, int depth, int channels );
......@@ -101,7 +101,7 @@ CVAPI(IplImage*) cvCreateImageHeader( CvSize size, int depth, int channels );
The returned IplImage\* points to the initialized header.
@param image Image header to initialize
@param size Image width and height
@param depth Image mDepthParam (see cvCreateImage )
@param depth Image depth (see cvCreateImage )
@param channels Number of channels (see cvCreateImage )
@param origin Top-left IPL_ORIGIN_TL or bottom-left IPL_ORIGIN_BL
@param align Alignment for image rows, typically 4 or 8 bytes
......@@ -114,11 +114,11 @@ CVAPI(IplImage*) cvInitImageHeader( IplImage* image, CvSize size, int depth,
This function call is equivalent to the following code:
@code
header = cvCreateImageHeader(size, mDepthParam, channels);
header = cvCreateImageHeader(size, depth, channels);
cvCreateData(header);
@endcode
@param size Image width and height
@param depth Bit mDepthParam of image elements. See IplImage for valid depths.
@param depth Bit depth of image elements. See IplImage for valid depths.
@param channels Number of channels per pixel. See IplImage for details. This function only creates
images with interleaved channels.
*/
......@@ -265,7 +265,7 @@ The function call is equivalent to the following code:
@param rows Number of rows in the matrix
@param cols Number of columns in the matrix
@param type The type of the matrix elements in the form
CV_\<bit mDepthParam\>\<S|U|F\>C\<number of channels\> , where S=signed, U=unsigned, F=float. For
CV_\<bit depth\>\<S|U|F\>C\<number of channels\> , where S=signed, U=unsigned, F=float. For
example, CV _ 8UC1 means the elements are 8-bit unsigned and the there is 1 channel, and CV _
32SC2 means the elements are 32-bit signed and there are 2 channels.
*/
......@@ -2860,7 +2860,7 @@ public:
size_t size() const;
//! returns the type of sequence elements (CV_8UC1 ... CV_64FC(CV_CN_MAX) ...)
int type() const;
//! returns the mDepthParam of sequence elements (CV_8U ... CV_64F)
//! returns the depth of sequence elements (CV_8U ... CV_64F)
int depth() const;
//! returns the number of channels in each sequence element
int channels() const;
......
......@@ -277,7 +277,7 @@ public:
/*! includes several bit-fields:
- the magic signature
- continuity flag
- mDepthParam
- depth
- number of channels
*/
int flags;
......
......@@ -68,13 +68,13 @@ install the library, configure header and library build paths.
//! convert OpenCV data type to hppDataType
inline int toHppType(const int cvType)
{
int mDepthParam = CV_MAT_DEPTH(cvType);
int hppType = mDepthParam == CV_8U ? HPP_DATA_TYPE_8U :
mDepthParam == CV_16U ? HPP_DATA_TYPE_16U :
mDepthParam == CV_16S ? HPP_DATA_TYPE_16S :
mDepthParam == CV_32S ? HPP_DATA_TYPE_32S :
mDepthParam == CV_32F ? HPP_DATA_TYPE_32F :
mDepthParam == CV_64F ? HPP_DATA_TYPE_64F : -1;
int depth = CV_MAT_DEPTH(cvType);
int hppType = depth == CV_8U ? HPP_DATA_TYPE_8U :
depth == CV_16U ? HPP_DATA_TYPE_16U :
depth == CV_16S ? HPP_DATA_TYPE_16S :
depth == CV_32S ? HPP_DATA_TYPE_32S :
depth == CV_32F ? HPP_DATA_TYPE_32F :
depth == CV_64F ? HPP_DATA_TYPE_64F : -1;
CV_Assert( hppType >= 0 );
return hppType;
}
......
......@@ -1205,7 +1205,7 @@ public:
\f[m(x,y) = saturate \_ cast<rType>( \alpha (*this)(x,y) + \beta )\f]
@param m output matrix; if it does not have a proper size or type before the operation, it is
reallocated.
@param rtype desired output matrix type or, rather, the mDepthParam since the number of channels are the
@param rtype desired output matrix type or, rather, the depth since the number of channels are the
same as the input has; if rtype is negative, the output matrix will have the same type as the input.
@param alpha optional scale factor.
@param beta optional delta added to the scaled values.
......@@ -1216,7 +1216,7 @@ public:
This is an internally used method called by the @ref MatrixExpressions engine.
@param m Destination array.
@param type Desired destination array mDepthParam (or -1 if it should be the same as the source type).
@param type Desired destination array depth (or -1 if it should be the same as the source type).
*/
void assignTo( Mat& m, int type=-1 ) const;
......@@ -1415,7 +1415,7 @@ public:
@code
Mat color;
...
Mat gray(color.rows, color.cols, color.mDepthParam());
Mat gray(color.rows, color.cols, color.depth());
cvtColor(color, gray, COLOR_BGR2GRAY);
@endcode
you can simply write:
......@@ -1735,9 +1735,9 @@ public:
*/
int type() const;
/** @brief Returns the mDepthParam of a matrix element.
/** @brief Returns the depth of a matrix element.
The method returns the identifier of the matrix element mDepthParam (the type of each individual channel).
The method returns the identifier of the matrix element depth (the type of each individual channel).
For example, for a 16-bit signed element array, the method returns CV_16S . A complete list of
matrix types contains the following values:
- CV_8U - 8-bit unsigned integers ( 0..255 )
......@@ -2048,7 +2048,7 @@ public:
/*! includes several bit-fields:
- the magic signature
- continuity flag
- mDepthParam
- depth
- number of channels
*/
int flags;
......@@ -2528,7 +2528,7 @@ public:
/*! includes several bit-fields:
- the magic signature
- continuity flag
- mDepthParam
- depth
- number of channels
*/
int flags;
......@@ -2716,7 +2716,7 @@ public:
/*!
@param [out] m - output matrix; if it does not have a proper size or type before the operation,
it is reallocated
@param [in] rtype - desired output matrix type or, rather, the mDepthParam since the number of channels
@param [in] rtype - desired output matrix type or, rather, the depth since the number of channels
are the same as the input has; if rtype is negative, the output matrix will have the
same type as the input.
@param [in] alpha - optional scale factor
......@@ -2750,7 +2750,7 @@ public:
//! returns type of sparse matrix elements
int type() const;
//! returns the mDepthParam of sparse matrix elements
//! returns the depth of sparse matrix elements
int depth() const;
//! returns the number of channels
int channels() const;
......@@ -2949,7 +2949,7 @@ public:
//! returns type of the matrix elements
int type() const;
//! returns mDepthParam of the matrix elements
//! returns depth of the matrix elements
int depth() const;
//! returns the number of channels in each matrix element
int channels() const;
......@@ -3623,7 +3623,7 @@ abs is a meta-function that is expanded to one of absdiff or convertScaleAbs for
beta)`
The output matrix has the same size and the same type as the input one except for the last case,
where C is mDepthParam=CV_8U .
where C is depth=CV_8U .
@param m matrix.
@sa @ref MatrixExpressions, absdiff, convertScaleAbs
*/
......
......@@ -105,8 +105,8 @@ public:
cols = n,
channels = rows*cols,
#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED
mDepthParam = traits::Type<_Tp>::value,
type = CV_MAKETYPE(mDepthParam, channels),
depth = traits::Type<_Tp>::value,
type = CV_MAKETYPE(depth, channels),
#endif
shortdim = (m < n ? m : n)
};
......@@ -265,8 +265,8 @@ public:
channels = m * n,
fmt = traits::SafeFmt<channel_type>::fmt + ((channels - 1) << 8)
#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED
,mDepthParam = DataType<channel_type>::mDepthParam
,type = CV_MAKETYPE(mDepthParam, channels)
,depth = DataType<channel_type>::depth
,type = CV_MAKETYPE(depth, channels)
#endif
};
};
......@@ -339,8 +339,8 @@ public:
enum {
channels = cn,
#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED
mDepthParam = Matx<_Tp, cn, 1>::mDepthParam,
type = CV_MAKETYPE(mDepthParam, channels),
depth = Matx<_Tp, cn, 1>::depth,
type = CV_MAKETYPE(depth, channels),
#endif
_dummy_enum_finalizer = 0
};
......@@ -442,8 +442,8 @@ public:
channels = cn,
fmt = DataType<channel_type>::fmt + ((channels - 1) << 8),
#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED
mDepthParam = DataType<channel_type>::mDepthParam,
type = CV_MAKETYPE(mDepthParam, channels),
depth = DataType<channel_type>::depth,
type = CV_MAKETYPE(depth, channels),
#endif
_dummy_enum_finalizer = 0
};
......
......@@ -371,7 +371,7 @@ public:
@param arr Destination array (host or device memory, can be Mat , cuda::GpuMat , ogl::Buffer or
ogl::Texture2D ).
@param ddepth Destination mDepthParam.
@param ddepth Destination depth.
@param autoRelease Auto release mode for destination buffer (if arr is OpenGL buffer or texture).
*/
void copyTo(OutputArray arr, int ddepth = CV_32F, bool autoRelease = false) const;
......
......@@ -61,7 +61,7 @@ namespace cv
A primitive OpenCV data type is one of unsigned char, bool, signed char, unsigned short, signed
short, int, float, double, or a tuple of values of one of these types, where all the values in the
tuple have the same type. Any primitive type from the list can be defined by an identifier in the
form CV_\<bit-mDepthParam\>{U|S|F}C(\<number_of_channels\>), for example: uchar \~ CV_8UC1, 3-element
form CV_\<bit-depth\>{U|S|F}C(\<number_of_channels\>), for example: uchar \~ CV_8UC1, 3-element
floating-point tuple \~ CV_32FC3, and so on. A universal OpenCV structure that is able to store a
single instance of such a primitive data type is Vec. Multiple instances of such a type can be
stored in a std::vector, Mat, Mat_, SparseMat, SparseMat_, or any other container that is able to
......@@ -86,9 +86,9 @@ DataType itself that is used but its specialized versions, such as:
typedef std::complex<_Tp> work_type;
typedef _Tp channel_type;
// DataDepth is another helper trait class
enum { mDepthParam = DataDepth<_Tp>::value, channels=2,
enum { depth = DataDepth<_Tp>::value, channels=2,
fmt=(channels-1)*256+DataDepth<_Tp>::fmt,
type=CV_MAKETYPE(mDepthParam, channels) };
type=CV_MAKETYPE(depth, channels) };
};
...
@endcode
......@@ -99,8 +99,8 @@ OpenCV-compatible data type identifier, for example:
Mat A(30, 40, DataType<float>::type);
Mat B = Mat_<std::complex<double> >(3, 3);
// the statement below will print 6, 2 , that is mDepthParam == CV_64F, channels == 2
cout << B.mDepthParam() << ", " << B.channels() << endl;
// the statement below will print 6, 2 , that is depth == CV_64F, channels == 2
cout << B.depth() << ", " << B.channels() << endl;
@endcode
So, such traits are used to tell OpenCV which data type you are working with, even if such a type is
not native to OpenCV. For example, the matrix B initialization above is compiled because OpenCV
......@@ -118,10 +118,10 @@ public:
typedef value_type channel_type;
typedef value_type vec_type;
enum { generic_type = 1,
mDepthParam = -1,
depth = -1,
channels = 1,
fmt = 0,
type = CV_MAKETYPE(mDepthParam, channels)
type = CV_MAKETYPE(depth, channels)
};
#endif
};
......@@ -283,50 +283,50 @@ public:
template<int _depth> class TypeDepth
{
#ifdef OPENCV_TRAITS_ENABLE_LEGACY_DEFAULTS
enum { mDepthParam = CV_USRTYPE1 };
enum { depth = CV_USRTYPE1 };
typedef void value_type;
#endif
};
template<> class TypeDepth<CV_8U>
{
enum { mDepthParam = CV_8U };
enum { depth = CV_8U };
typedef uchar value_type;
};
template<> class TypeDepth<CV_8S>
{
enum { mDepthParam = CV_8S };
enum { depth = CV_8S };
typedef schar value_type;
};
template<> class TypeDepth<CV_16U>
{
enum { mDepthParam = CV_16U };
enum { depth = CV_16U };
typedef ushort value_type;
};
template<> class TypeDepth<CV_16S>
{
enum { mDepthParam = CV_16S };
enum { depth = CV_16S };
typedef short value_type;
};
template<> class TypeDepth<CV_32S>
{
enum { mDepthParam = CV_32S };
enum { depth = CV_32S };
typedef int value_type;
};
template<> class TypeDepth<CV_32F>
{
enum { mDepthParam = CV_32F };
enum { depth = CV_32F };
typedef float value_type;
};
template<> class TypeDepth<CV_64F>
{
enum { mDepthParam = CV_64F };
enum { depth = CV_64F };
typedef double value_type;
};
......
......@@ -101,8 +101,8 @@ public:
channels = 2,
fmt = DataType<channel_type>::fmt + ((channels - 1) << 8)
#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED
,mDepthParam = DataType<channel_type>::mDepthParam
,type = CV_MAKETYPE(mDepthParam, channels)
,depth = DataType<channel_type>::depth
,type = CV_MAKETYPE(depth, channels)
#endif
};
......@@ -202,8 +202,8 @@ public:
channels = 2,
fmt = traits::SafeFmt<channel_type>::fmt + ((channels - 1) << 8)
#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED
,mDepthParam = DataType<channel_type>::mDepthParam
,type = CV_MAKETYPE(mDepthParam, channels)
,depth = DataType<channel_type>::depth
,type = CV_MAKETYPE(depth, channels)
#endif
};
......@@ -281,8 +281,8 @@ public:
channels = 3,
fmt = traits::SafeFmt<channel_type>::fmt + ((channels - 1) << 8)
#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED
,mDepthParam = DataType<channel_type>::mDepthParam
,type = CV_MAKETYPE(mDepthParam, channels)
,depth = DataType<channel_type>::depth
,type = CV_MAKETYPE(depth, channels)
#endif
};
......@@ -351,8 +351,8 @@ public:
channels = 2,
fmt = DataType<channel_type>::fmt + ((channels - 1) << 8)
#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED
,mDepthParam = DataType<channel_type>::mDepthParam
,type = CV_MAKETYPE(mDepthParam, channels)
,depth = DataType<channel_type>::depth
,type = CV_MAKETYPE(depth, channels)
#endif
};
......@@ -461,8 +461,8 @@ public:
channels = 4,
fmt = traits::SafeFmt<channel_type>::fmt + ((channels - 1) << 8)
#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED
,mDepthParam = DataType<channel_type>::mDepthParam
,type = CV_MAKETYPE(mDepthParam, channels)
,depth = DataType<channel_type>::depth
,type = CV_MAKETYPE(depth, channels)
#endif
};
......@@ -546,8 +546,8 @@ public:
channels = (int)sizeof(value_type)/sizeof(channel_type), // 5
fmt = traits::SafeFmt<channel_type>::fmt + ((channels - 1) << 8)
#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED
,mDepthParam = DataType<channel_type>::mDepthParam
,type = CV_MAKETYPE(mDepthParam, channels)
,depth = DataType<channel_type>::depth
,type = CV_MAKETYPE(depth, channels)
#endif
};
......@@ -610,8 +610,8 @@ public:
channels = 2,
fmt = traits::SafeFmt<channel_type>::fmt + ((channels - 1) << 8)
#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED
,mDepthParam = DataType<channel_type>::mDepthParam
,type = CV_MAKETYPE(mDepthParam, channels)
,depth = DataType<channel_type>::depth
,type = CV_MAKETYPE(depth, channels)
#endif
};
......@@ -674,8 +674,8 @@ public:
channels = 4,
fmt = traits::SafeFmt<channel_type>::fmt + ((channels - 1) << 8)
#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED
,mDepthParam = DataType<channel_type>::mDepthParam
,type = CV_MAKETYPE(mDepthParam, channels)
,depth = DataType<channel_type>::depth
,type = CV_MAKETYPE(depth, channels)
#endif
};
......@@ -783,10 +783,10 @@ public:
typedef float channel_type;
enum { generic_type = 0,
mDepthParam = DataType<channel_type>::mDepthParam,
depth = DataType<channel_type>::depth,
channels = (int)(sizeof(value_type)/sizeof(channel_type)), // 7
fmt = DataType<channel_type>::fmt + ((channels - 1) << 8),
type = CV_MAKETYPE(mDepthParam, channels)
type = CV_MAKETYPE(depth, channels)
};
typedef Vec<channel_type, channels> vec_type;
......@@ -827,10 +827,10 @@ public:
typedef int channel_type;
enum { generic_type = 0,
mDepthParam = DataType<channel_type>::mDepthParam,
depth = DataType<channel_type>::depth,
channels = (int)(sizeof(value_type)/sizeof(channel_type)), // 4
fmt = DataType<channel_type>::fmt + ((channels - 1) << 8),
type = CV_MAKETYPE(mDepthParam, channels)
type = CV_MAKETYPE(depth, channels)
};
typedef Vec<channel_type, channels> vec_type;
......@@ -952,8 +952,8 @@ public:
channels = (int)(sizeof(value_type)/sizeof(channel_type)), // 24
fmt = DataType<channel_type>::fmt + ((channels - 1) << 8)
#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED
,mDepthParam = DataType<channel_type>::mDepthParam
,type = CV_MAKETYPE(mDepthParam, channels)
,depth = DataType<channel_type>::depth
,type = CV_MAKETYPE(depth, channels)
#endif
};
......
......@@ -134,7 +134,7 @@ enum {
CV_BadModelOrChSeq= -14, /**/
CV_BadNumChannels= -15, /**< bad number of channels, for example, some functions accept only single channel matrices */
CV_BadNumChannel1U= -16, /**/
CV_BadDepth= -17, /**< input image mDepthParam is not supported by the function */
CV_BadDepth= -17, /**< input image depth is not supported by the function */
CV_BadAlphaChannel= -18, /**/
CV_BadOrder= -19, /**< number of dimensions is out of range */
CV_BadOrigin= -20, /**< incorrect input origin */
......@@ -303,7 +303,7 @@ _IplImage
int ID; /**< version (=0)*/
int nChannels; /**< Most of OpenCV functions support 1,2,3 or 4 channels */
int alphaChannel; /**< Ignored by OpenCV */
int depth; /**< Pixel mDepthParam in bits: IPL_DEPTH_8U, IPL_DEPTH_8S, IPL_DEPTH_16S,
int depth; /**< Pixel depth in bits: IPL_DEPTH_8U, IPL_DEPTH_8S, IPL_DEPTH_16S,
IPL_DEPTH_32S, IPL_DEPTH_32F and IPL_DEPTH_64F are supported. */
char colorModel[4]; /**< Ignored by OpenCV */
char channelSeq[4]; /**< ditto */
......
......@@ -197,7 +197,7 @@ public:
// Number of bytes per pixel
int PixelSize() const {return Channels() * ChannelSize(); }
// Return mDepthParam type (e.g. IPL_DEPTH_8U, IPL_DEPTH_32F) which is the number
// Return depth type (e.g. IPL_DEPTH_8U, IPL_DEPTH_32F) which is the number
// of bits per channel and with the signed bit set.
// This is known at compile time using specializations.
int Depth() const;
......@@ -236,11 +236,11 @@ protected:
void operator=(const WImage&);
explicit WImage(IplImage* img) : image_(img) {
assert(!img || img->mDepthParam == Depth());
assert(!img || img->depth == Depth());
}
void SetIpl(IplImage* image) {
assert(!image || image->mDepthParam == Depth());
assert(!image || image->depth == Depth());
image_ = image;
}
......@@ -283,7 +283,7 @@ protected:
void operator=(const WImageC&);
void SetIpl(IplImage* image) {
assert(!image || image->mDepthParam == WImage<T>::Depth());
assert(!image || image->depth == WImage<T>::Depth());
WImage<T>::SetIpl(image);
}
};
......@@ -491,7 +491,7 @@ protected:
};
// Specializations for mDepthParam
// Specializations for depth
template<>
inline int WImage<uchar>::Depth() const {return IPL_DEPTH_8U; }
template<>
......
......@@ -356,7 +356,7 @@ CV_EXPORTS_W int waitKey(int delay = 0);
The function imshow displays an image in the specified window. If the window was created with the
cv::WINDOW_AUTOSIZE flag, the image is shown with its original size, however it is still limited by the screen resolution.
Otherwise, the image is scaled to fit the window. The function may scale the image, depending on its mDepthParam:
Otherwise, the image is scaled to fit the window. The function may scale the image, depending on its depth:
- If the image is 8-bit unsigned, it is displayed as is.
- If the image is 16-bit unsigned or 32-bit integer, the pixels are divided by 256. That is, the
......
......@@ -65,7 +65,7 @@ enum ImreadModes {
IMREAD_UNCHANGED = -1, //!< If set, return the loaded image as is (with alpha channel, otherwise it gets cropped).
IMREAD_GRAYSCALE = 0, //!< If set, always convert image to the single channel grayscale image.
IMREAD_COLOR = 1, //!< If set, always convert image to the 3 channel BGR color image.
IMREAD_ANYDEPTH = 2, //!< If set, return 16-bit/32-bit image when the input has the corresponding mDepthParam, otherwise convert it to 8-bit.
IMREAD_ANYDEPTH = 2, //!< If set, return 16-bit/32-bit image when the input has the corresponding depth, otherwise convert it to 8-bit.
IMREAD_ANYCOLOR = 4, //!< If set, the image is read in any possible color format.
IMREAD_LOAD_GDAL = 8, //!< If set, use the gdal driver for loading the image.
IMREAD_REDUCED_GRAYSCALE_2 = 16, //!< If set, always convert image to the single channel grayscale image and the image size reduced 1/2.
......@@ -180,7 +180,7 @@ CV_EXPORTS_W bool imreadmulti(const String& filename, CV_OUT std::vector<Mat>& m
The function imwrite saves the image to the specified file. The image format is chosen based on the
filename extension (see cv::imread for the list of extensions). Only 8-bit (or 16-bit unsigned (CV_16U)
in case of PNG, JPEG 2000, and TIFF) single-channel or 3-channel (with 'BGR' channel order) images
can be saved using this function. If the format, mDepthParam or channel order is different, use
can be saved using this function. If the format, depth or channel order is different, use
Mat::convertTo , and cv::cvtColor to convert it before saving. Or, use the universal FileStorage I/O
functions to save the image to XML or YAML format.
......
......@@ -60,7 +60,7 @@ enum
CV_LOAD_IMAGE_GRAYSCALE =0,
/* ?, color */
CV_LOAD_IMAGE_COLOR =1,
/* any mDepthParam, ? */
/* any depth, ? */
CV_LOAD_IMAGE_ANYDEPTH =2,
/* ?, any color */
CV_LOAD_IMAGE_ANYCOLOR =4,
......
......@@ -1053,9 +1053,9 @@ public:
/** @copybrief getMaxCategories @see getMaxCategories */
CV_WRAP virtual void setMaxCategories(int val) = 0;
/** The maximum possible mDepthParam of the tree.
That is the training algorithms attempts to split a node while its mDepthParam is less than maxDepthDistance.
The root node has zero mDepthParam. The actual mDepthParam may be smaller if the other termination criteria
/** The maximum possible depth of the tree.
That is the training algorithms attempts to split a node while its depth is less than maxDepth.
The root node has zero depth. The actual depth may be smaller if the other termination criteria
are met (see the outline of the training procedure @ref ml_intro_trees "here"), and/or if the
tree is pruned. Default value is INT_MAX.*/
/** @see setMaxDepth */
......@@ -1369,7 +1369,7 @@ public:
Params();
Params( int lossFunctionType, int weakCount, float shrinkage,
float subsamplePortion, int maxDepthDistance, bool useSurrogates );
float subsamplePortion, int maxDepth, bool useSurrogates );
};
enum {SQUARED_LOSS=0, ABSOLUTE_LOSS, HUBER_LOSS=3, DEVIANCE_LOSS};
......
......@@ -108,8 +108,8 @@ CVAPI(void) cvCalcOpticalFlowFarneback( const CvArr* prev, const CvArr* next,
/****************************************************************************************\
* All the motion template functions work only with single channel images. *
* Silhouette image must have mDepthParam IPL_DEPTH_8U or IPL_DEPTH_8S *
* Motion history image must have mDepthParam IPL_DEPTH_32F, *
* Silhouette image must have depth IPL_DEPTH_8U or IPL_DEPTH_8S *
* Motion history image must have depth IPL_DEPTH_32F, *
* Gradient mask - IPL_DEPTH_8U or IPL_DEPTH_8S, *
* Motion orientation image - IPL_DEPTH_32F *
* Segmentation mask - IPL_DEPTH_32F *
......
......@@ -225,8 +225,8 @@ enum { CAP_PROP_OPENNI_OUTPUT_MODE = 100,
CAP_PROP_OPENNI_FRAME_MAX_DEPTH = 101, //!< In mm
CAP_PROP_OPENNI_BASELINE = 102, //!< In mm
CAP_PROP_OPENNI_FOCAL_LENGTH = 103, //!< In pixels
CAP_PROP_OPENNI_REGISTRATION = 104, //!< Flag that synchronizes the remapping mDepthParam map to image map
//!< by changing mDepthParam generator's view point (if the flag is "on") or
CAP_PROP_OPENNI_REGISTRATION = 104, //!< Flag that synchronizes the remapping depth map to image map
//!< by changing depth generator's view point (if the flag is "on") or
//!< sets this view point to its normal one (if the flag is "off").
CAP_PROP_OPENNI_REGISTRATION_ON = CAP_PROP_OPENNI_REGISTRATION,
CAP_PROP_OPENNI_APPROX_FRAME_SYNC = 105,
......@@ -249,7 +249,7 @@ enum { CAP_OPENNI_IMAGE_GENERATOR_PRESENT = CAP_OPENNI_IMAGE_GENERATOR +
CAP_OPENNI_IR_GENERATOR_PRESENT = CAP_OPENNI_IR_GENERATOR + CAP_PROP_OPENNI_GENERATOR_PRESENT,
};
//! OpenNI data given from mDepthParam generator
//! OpenNI data given from depth generator
enum { CAP_OPENNI_DEPTH_MAP = 0, //!< Depth values in mm (CV_16UC1)
CAP_OPENNI_POINT_CLOUD_MAP = 1, //!< XYZ in meters (CV_32FC3)
CAP_OPENNI_DISPARITY_MAP = 2, //!< Disparity in pixels (CV_8UC1)
......@@ -380,8 +380,8 @@ enum { CAP_PROP_XI_DOWNSAMPLING = 400, //!< Chan
CAP_PROP_XI_REGION_SELECTOR = 589, //!< Selects Region in Multiple ROI which parameters are set by width, height, ... ,region mode.
CAP_PROP_XI_REGION_MODE = 595, //!< Activates/deactivates Region selected by Region Selector.
CAP_PROP_XI_LIMIT_BANDWIDTH = 459, //!< Set/get bandwidth(datarate)(in Megabits).
CAP_PROP_XI_SENSOR_DATA_BIT_DEPTH = 460, //!< Sensor output data bit mDepthParam.
CAP_PROP_XI_OUTPUT_DATA_BIT_DEPTH = 461, //!< Device output data bit mDepthParam.
CAP_PROP_XI_SENSOR_DATA_BIT_DEPTH = 460, //!< Sensor output data bit depth.
CAP_PROP_XI_OUTPUT_DATA_BIT_DEPTH = 461, //!< Device output data bit depth.
CAP_PROP_XI_IMAGE_DATA_BIT_DEPTH = 462, //!< bitdepth of data returned by function xiGetImage.
CAP_PROP_XI_OUTPUT_DATA_PACKING = 463, //!< Device output data packing (or grouping) enabled. Packing could be enabled if output_data_bit_depth > 8 and packing capability is available.
CAP_PROP_XI_OUTPUT_DATA_PACKING_TYPE = 464, //!< Data packing type. Some cameras supports only specific packing type.
......@@ -529,8 +529,8 @@ enum { CAP_INTELPERC_DEPTH_GENERATOR = 1 << 29,
CAP_INTELPERC_GENERATORS_MASK = CAP_INTELPERC_DEPTH_GENERATOR + CAP_INTELPERC_IMAGE_GENERATOR
};
enum { CAP_INTELPERC_DEPTH_MAP = 0, //!< Each pixel is a 16-bit integer. The value indicates the distance from an object to the camera's XY plane or the Cartesian mDepthParam.
CAP_INTELPERC_UVDEPTH_MAP = 1, //!< Each pixel contains two 32-bit floating point values in the range of 0-1, representing the mapping of mDepthParam coordinates to the color coordinates.
enum { CAP_INTELPERC_DEPTH_MAP = 0, //!< Each pixel is a 16-bit integer. The value indicates the distance from an object to the camera's XY plane or the Cartesian depth.
CAP_INTELPERC_UVDEPTH_MAP = 1, //!< Each pixel contains two 32-bit floating point values in the range of 0-1, representing the mapping of depth coordinates to the color coordinates.
CAP_INTELPERC_IR_MAP = 2, //!< Each pixel is a 16-bit integer. The value indicates the intensity of the reflected laser beam.
CAP_INTELPERC_IMAGE = 3
};
......
......@@ -224,8 +224,8 @@ enum
CV_CAP_PROP_OPENNI_BASELINE = 102, // in mm
CV_CAP_PROP_OPENNI_FOCAL_LENGTH = 103, // in pixels
CV_CAP_PROP_OPENNI_REGISTRATION = 104, // flag
CV_CAP_PROP_OPENNI_REGISTRATION_ON = CV_CAP_PROP_OPENNI_REGISTRATION, // flag that synchronizes the remapping mDepthParam map to image map
// by changing mDepthParam generator's view point (if the flag is "on") or
CV_CAP_PROP_OPENNI_REGISTRATION_ON = CV_CAP_PROP_OPENNI_REGISTRATION, // flag that synchronizes the remapping depth map to image map
// by changing depth generator's view point (if the flag is "on") or
// sets this view point to its normal one (if the flag is "off").
CV_CAP_PROP_OPENNI_APPROX_FRAME_SYNC = 105,
CV_CAP_PROP_OPENNI_MAX_BUFFER_SIZE = 106,
......@@ -310,8 +310,8 @@ enum
CV_CAP_PROP_XI_REGION_SELECTOR = 589, // Selects Region in Multiple ROI which parameters are set by width, height, ... ,region mode
CV_CAP_PROP_XI_REGION_MODE = 595, // Activates/deactivates Region selected by Region Selector
CV_CAP_PROP_XI_LIMIT_BANDWIDTH = 459, // Set/get bandwidth(datarate)(in Megabits)
CV_CAP_PROP_XI_SENSOR_DATA_BIT_DEPTH = 460, // Sensor output data bit mDepthParam.
CV_CAP_PROP_XI_OUTPUT_DATA_BIT_DEPTH = 461, // Device output data bit mDepthParam.
CV_CAP_PROP_XI_SENSOR_DATA_BIT_DEPTH = 460, // Sensor output data bit depth.
CV_CAP_PROP_XI_OUTPUT_DATA_BIT_DEPTH = 461, // Device output data bit depth.
CV_CAP_PROP_XI_IMAGE_DATA_BIT_DEPTH = 462, // bitdepth of data returned by function xiGetImage
CV_CAP_PROP_XI_OUTPUT_DATA_PACKING = 463, // Device output data packing (or grouping) enabled. Packing could be enabled if output_data_bit_depth > 8 and packing capability is available.
CV_CAP_PROP_XI_OUTPUT_DATA_PACKING_TYPE = 464, // Data packing type. Some cameras supports only specific packing type.
......@@ -464,7 +464,7 @@ enum
enum
{
// Data given from mDepthParam generator.
// Data given from depth generator.
CV_CAP_OPENNI_DEPTH_MAP = 0, // Depth values in mm (CV_16UC1)
CV_CAP_OPENNI_POINT_CLOUD_MAP = 1, // XYZ in meters (CV_32FC3)
CV_CAP_OPENNI_DISPARITY_MAP = 2, // Disparity in pixels (CV_8UC1)
......@@ -491,8 +491,8 @@ enum
enum
{
CV_CAP_INTELPERC_DEPTH_MAP = 0, // Each pixel is a 16-bit integer. The value indicates the distance from an object to the camera's XY plane or the Cartesian mDepthParam.
CV_CAP_INTELPERC_UVDEPTH_MAP = 1, // Each pixel contains two 32-bit floating point values in the range of 0-1, representing the mapping of mDepthParam coordinates to the color coordinates.
CV_CAP_INTELPERC_DEPTH_MAP = 0, // Each pixel is a 16-bit integer. The value indicates the distance from an object to the camera's XY plane or the Cartesian depth.
CV_CAP_INTELPERC_UVDEPTH_MAP = 1, // Each pixel contains two 32-bit floating point values in the range of 0-1, representing the mapping of depth coordinates to the color coordinates.
CV_CAP_INTELPERC_IR_MAP = 2, // Each pixel is a 16-bit integer. The value indicates the intensity of the reflected laser beam.
CV_CAP_INTELPERC_IMAGE = 3
};
......
......@@ -4,6 +4,7 @@ import android.content.Context;
import com.wmdigit.core.catering.PlateDetectionManager;
import com.wmdigit.core.catering.TargetDetectionManager;
import com.wmdigit.core.hnsw.HnswManager;
import com.wmdigit.core.videopipe.VideoPipeManager;
/**
......@@ -33,9 +34,8 @@ public class CoreModule {
PlateDetectionManager.getInstance().initPlateDetection();
// 初始化视频流
VideoPipeManager.getInstance().initVideoPipe();
// todo 初始化索引库
// todo 初始化特征对比库
// 初始化索引库
HnswManager.getInstance().init();
}
public static Context getAppContext() {
......
......@@ -41,9 +41,16 @@ public class PlateDetectionManager {
return instance;
}
/**
* 同步锁
*/
private final Object syncLock = new Object();
public void initPlateDetection(){
int ret = init();
XLog.i("目标检测算法初始化结果:%s", ret);
synchronized (syncLock) {
int ret = init();
XLog.i("目标检测算法初始化结果:%s", ret);
}
}
/**
......@@ -56,13 +63,15 @@ public class PlateDetectionManager {
}
public TargetDetectResult detectImage(Bitmap bitmap){
long startTime = System.currentTimeMillis();
TargetDetectResult result = process(bitmap);
// 去掉最后一位逗号
if (result.getResults().endsWith(",")){
result.setResults(result.getResults().substring(0, result.getResults().length()-1));
synchronized (syncLock) {
long startTime = System.currentTimeMillis();
TargetDetectResult result = process(bitmap);
// 去掉最后一位逗号
if (result.getResults().endsWith(",")) {
result.setResults(result.getResults().substring(0, result.getResults().length() - 1));
}
XLog.i("推理耗时:" + (System.currentTimeMillis() - startTime) + "ms, 结果:" + result.getResults());
return result;
}
XLog.i("推理耗时:" + (System.currentTimeMillis() - startTime) + "ms, 结果:" + result.getResults());
return result;
}
}
......@@ -41,12 +41,19 @@ public class TargetDetectionManager {
return instance;
}
/**
* 同步锁
*/
private final Object syncLock = new Object();
/**
* 初始化
*/
public void initTargetDetection(){
int ret = init();
XLog.i("目标检测算法初始化结果:%s", ret);
synchronized (syncLock) {
int ret = init();
XLog.i("目标检测算法初始化结果:%s", ret);
}
}
/**
......@@ -59,14 +66,16 @@ public class TargetDetectionManager {
}
public TargetDetectResult detectImage(Bitmap bitmap){
long startTime = System.currentTimeMillis();
TargetDetectResult result = process(bitmap);
// 去掉最后一位逗号
if (result.getResults().endsWith(",")){
result.setResults(result.getResults().substring(0, result.getResults().length()-1));
synchronized (syncLock) {
long startTime = System.currentTimeMillis();
TargetDetectResult result = process(bitmap);
// 去掉最后一位逗号
if (result.getResults().endsWith(",")) {
result.setResults(result.getResults().substring(0, result.getResults().length() - 1));
}
XLog.i("推理耗时:" + (System.currentTimeMillis() - startTime) + "ms, 结果:" + result.getResults());
return result;
}
XLog.i("推理耗时:" + (System.currentTimeMillis() - startTime) + "ms, 结果:" + result.getResults());
return result;
}
}
package com.wmdigit.core.hnsw;
/**
* 向量索引算法
* @author dizi
*/
public class HnswManager {
static{
System.loadLibrary("features_hnsw");
}
/**
* 初始化方法
* @return
*/
public native int init();
/**
* 写入索引
* @param id 数据库自增ID
* @param code 商品CODE
* @param feature 商品特征
* @return 需要在数据库中删除的主键值 -1:无需删除 0:需要删除
*/
public native long writeSample(long id, String code, float[] feature);
/**
* 检索出最相似的结果
* @param feature
* @param threshold
* @return
*/
public native String retrieveMostSimilarResult(float[] feature, float threshold);
/**
* 删除所有Sample
*/
public native void deleteAllSample();
private static HnswManager instance;
public static HnswManager getInstance(){
if (instance == null){
synchronized (HnswManager.class){
if (instance == null){
instance = new HnswManager();
}
}
}
return instance;
}
/**
* 同步锁
*/
private final Object syncLock = new Object();
}
......@@ -51,28 +51,35 @@ public class VideoPipeManager {
return instance;
}
/**
* 同步锁
*/
private final Object syncLock = new Object();
/**
* 初始化视频流算法
*/
public void initVideoPipe(){
// 拷贝模型文件
String modelRootPath = CoreModule.getAppContext().getExternalFilesDir("model").getAbsolutePath();
String modelBackBonePath = modelRootPath + "/lat3d_backbone.rknn";
String modelC3dPath = modelRootPath + "/lat3d_c3d.rknn";
File fileBackBone = new File(modelBackBonePath);
File fileC3d = new File(modelC3dPath);
// 检查本地是否有模型文件
if (!fileBackBone.exists() || !fileC3d.exists()){
// 将assert模型文件输出到disk
try {
FileUtils.copyAssertsFolderToDisk(CoreModule.getAppContext(), "model", modelRootPath);
} catch (IOException e) {
XLog.e(e.toString());
synchronized (syncLock) {
// 拷贝模型文件
String modelRootPath = CoreModule.getAppContext().getExternalFilesDir("model").getAbsolutePath();
String modelBackBonePath = modelRootPath + "/lat3d_backbone.rknn";
String modelC3dPath = modelRootPath + "/lat3d_c3d.rknn";
File fileBackBone = new File(modelBackBonePath);
File fileC3d = new File(modelC3dPath);
// 检查本地是否有模型文件
if (!fileBackBone.exists() || !fileC3d.exists()) {
// 将assert模型文件输出到disk
try {
FileUtils.copyAssertsFolderToDisk(CoreModule.getAppContext(), "model", modelRootPath);
} catch (IOException e) {
XLog.e(e.toString());
}
}
// 初始化模型
int ret = init(modelBackBonePath, modelC3dPath);
XLog.i("视频流初始化结果:" + ret);
}
// 初始化模型
int ret = init(modelBackBonePath, modelC3dPath);
XLog.i("视频流初始化结果:" + ret);
}
/**
......@@ -80,8 +87,10 @@ public class VideoPipeManager {
* @param bitmap
*/
public void setEmptyImage(Bitmap bitmap){
int ret = setMarkMat(bitmap);
XLog.i("设置空盘结果:" + ret);
synchronized (syncLock) {
int ret = setMarkMat(bitmap);
XLog.i("设置空盘结果:" + ret);
}
}
/**
......@@ -89,7 +98,9 @@ public class VideoPipeManager {
* @param bitmap
*/
public void processImage(Bitmap bitmap){
feedFrame(bitmap);
synchronized (syncLock) {
feedFrame(bitmap);
}
}
public void objectIn(){
......
......@@ -8,4 +8,5 @@ v1.0.2 2024/08/06 1.增加系统信息页
5.增加数据管理页
6.增加学习页
7.增加AIDL服务
8.集成标框、菜品识别、餐盘识别算法
\ No newline at end of file
8.集成标框、菜品识别、餐盘识别算法
9.集成索引库算法(索引库版本较老,可能存在最后一条索引删除不掉的BUG)
\ No newline at end of file
......@@ -20,6 +20,8 @@ public class SystemInfoFragment extends BaseMvvmFragment<SystemInfoViewModel, Fr
@Override
protected void initObserve() {
// 识别模式监听
mViewModel.aiMode.observe(this, position-> mViewModel.saveAiMode(position));
}
@Override
......@@ -33,9 +35,6 @@ public class SystemInfoFragment extends BaseMvvmFragment<SystemInfoViewModel, Fr
mDataBinding.setViewModel(mViewModel);
// 设置下拉框列表
mDataBinding.spinnerAiMode.setSpinnerEntriesFromResource(R.array.array_ai_mode);
// todo 测试
// TargetDetectionManager.getInstance().detectImage(requireContext().getExternalFilesDir("images").getAbsolutePath() + "/7.jpg");
PlateDetectionManager.getInstance().detectImage(requireContext().getExternalFilesDir("images").getAbsolutePath() + "/7.jpg");
}
@Override
......
......@@ -8,7 +8,9 @@ import androidx.databinding.ObservableField;
import com.elvishew.xlog.XLog;
import com.wmdigit.common.base.mvvm.BaseViewModel;
import com.wmdigit.common.base.mvvm.SingleLiveEvent;
import com.wmdigit.common.utils.DeviceUtils;
import com.wmdigit.data.mmkv.repository.AiLocalRepository;
import com.wmdigit.data.mmkv.repository.CropLocalRepository;
import com.wmdigit.data.mmkv.repository.UserLocalRepository;
......@@ -53,6 +55,10 @@ public class SystemInfoViewModel extends BaseViewModel {
* 裁剪状态
*/
public ObservableField<Boolean> isCrop = new ObservableField<>();
/**
* 识别模式 0-菜品识别 1-餐盘识别
*/
public SingleLiveEvent<Integer> aiMode = new SingleLiveEvent<>();
public SystemInfoViewModel(@NonNull Application application) {
super(application);
......@@ -87,6 +93,8 @@ public class SystemInfoViewModel extends BaseViewModel {
}
// 获取裁剪状态
isCrop.set(CropLocalRepository.getInstance().getHasCropped());
// 获取AI模式
aiMode.postValue(AiLocalRepository.getInstance().getAiMode());
}
/**
......@@ -96,4 +104,12 @@ public class SystemInfoViewModel extends BaseViewModel {
}
/**
* 保存识别模式
* @param position
*/
public void saveAiMode(int position){
AiLocalRepository.getInstance().setAiMode(position);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment