shimat / opencvsharp

OpenCV wrapper for .NET
Apache License 2.0
5.43k stars 1.15k forks source link

how using Introduction to Principal Component Analysis (PCA) #1485

Closed AbdalaMask closed 1 year ago

AbdalaMask commented 2 years ago

how using Introduction to Principal Component Analysis (PCA)

void Get_Featurevector_Using_PCA(Mat sample,vector &Featur_Vector)

{ PCA pca_test; Mat reshaped; Mat result_image; / this part to extract data from pca file/ //to read pca data from xml file to use it to project feature vector FileStorage fs1("pca_data",FileStorage::READ); fs1["mean"] >> pca_test.mean ; //cout<<pca_test.mean<<endl; fs1["e_vectors"] >> pca_test.eigenvectors ; fs1["e_values"] >> pca_test.eigenvalues ; fs1.release(); int size=sample.rowssample.cols; /to convert matrix to vector/ reshaped=sample; reshaped=sample.reshape(1,size); reshaped.convertTo(reshaped,CV_32FC1,1/255.);//convert to float data type to deal with pca /end conversion*/ pca_test.project(reshaped,result_image); Featur_Vector=result_image;

} how convert to c# plsssss

AbdalaMask commented 2 years ago

plass help

AbdalaMask commented 2 years ago

void cv::operator>>(const cv::FileNode &n, cv::Mat &value)

shimat commented 2 years ago

http://shimat.github.io/opencvsharp/api/OpenCvSharp.FileNode.html#OpenCvSharp_FileNode_ReadMat_OpenCvSharp_Mat_

using var fs = new FileStorage("pca_data", FileStorage.Modes.Read))
using var eigenvectors = fs["e_vectors"]?.ReadMat();
...
AbdalaMask commented 2 years ago

thank you for replying

I used FileStorage fs1 = new FileStorage("LicensePlate/pca_data.yml", FileStorage.Modes.Read);

        pca_test.Read(fs1.Root());
stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.