Я пытаюсь создать DLL с включенным OpenCV PCA, чтобы сделать его пригодным для использования в Labview.Pass cv :: Mat to labview
Я определил функцию:
extern "C" __declspec(dllexport) int __cdecl doPCA(float *input,int32_t input_rows,int32_t input_cols,double maxComponents,float *output);
И написал это нравится:
int __cdecl doPCA(float *input,int32_t input_rows, int32_t input_cols,double maxComponents,float *output)
{
Mat pcaset = Mat(input_rows,input_cols, CV_32FC1, &input); //CV_32FC1 is for float valued pixel
PCA pca(pcaset, // pass the data
Mat(), // we do not have a pre-computed mean vector, // so let the PCA engine to compute it
CV_PCA_DATA_AS_ROW, // indicate that the vectors// are stored as matrix rows// (use PCA::DATA_AS_COL if the vectors are // the matrix columns)
2 // specify, how many principal components to retain
);
int i, j;
for(i = 0; i < input_rows; i++)
{
for(j = 0; j < input_cols; j++)
{
output[(i * input_cols) + j] = pca.eigenvectors.data[(i * input_cols) + j]; // Write Values to 1D output array
}
}
if(pca.eigenvectors.empty()){return 0;} // is empty
if(!pca.eigenvectors.empty()){return 1;} // is not empty
}
В Labview стороне получить доступ к функции с помощью скомпилированного DLL:
Но я не могу понять, как передать значение от pca.eigenvectors
cv::Mat
в массив 1D поплавкового вывода.
int i, j;
for(i = 0; i < input_rows; i++)
{
for(j = 0; j < input_cols; j++)
{
output[(i * input_cols) + j] = pca.eigenvectors.data[(i * input_cols) + j]; // Write Values to 1D output array
}
}
Может ли кто-нибудь дать подсказку?
Посмотрите [здесь] (http://docs.opencv.org/3.1.0/d1/dee/tutorial_introduction_to_pca.html#gsc.tab = 0), чтобы знать, как правильно обращаться к собственным векторам. Это просто 'n_of_principal_components x dimension' (а не' input_rows x input_cols'), и они 'double' – Miki