I was wondering if it was possible to export (write) a CvRTrees object (effectively the forest of trees) to a file, and then import that model into a different OpenCV session.
I ask as my training/test system is separate from the on-line system, and being able to move the model between the two would be a huge help.
I'm using OpenCV v 2.4.10
Thanks!!
I also had the same problem and it seems that the documentation is a bit poor.
I had a look at the source code and there are two functions which should solve your problem:
void CvRTrees::write( CvFileStorage* fs, const char* name ) const
void CvRTrees::read( CvFileStorage* fs, CvFileNode* fnode )
Related
I have retrained the inception model to recognize custom set of images. I have tried the simple and camera examples and replaced the .pb and .txt files with my own files. I am able to get a reliable result of probability of 0.99 when using the simple example (replaced the grace_hopper with my image). However, I got different results when using the camera example. I point my camera to the photo but the result seems different from that obtained from simple example. The config I am using is as follows, is there any config I need to make? Thank you.
const int wanted_input_width = 299;
const int wanted_input_height = 299;
const int wanted_input_channels = 3;
const float input_mean = 128.0f;
const float input_std = 128.0f;
const std::string input_layer_name = "Mul";
const std::string output_layer_name = "final_result";
The input/output layers have changed between Inception v1 (the version packaged with the Android demo) and v3 (the one you retrained).
You'll need to update the constants found in in ClassifierActivity.java with the values for Inception v3 (also found in the comments there).
I am building an image processing application using OpenCV. I am also using the Armadillo library because it has some very neat matrix related functions. The thing is though, in order to use Armadillo functions on cv::Mat I need frequent conversions from cv::Mat to arma::Mat .
To accomplish this I convert the cv::Mat to an arma::Mat using a function like this
arma::Mat cvMat2armaMat(cv::Mat M)
{
copy cv::Mat data to a arma::Mat
return arma::Mat
}
Is there a more efficient way of doing this?
To avoid or reduce copying, you can access the memory used by Armadillo matrices via the .memptr() member function. For example:
mat X(5,6);
double* mem = X.memptr();
Be careful when using the above, as you're not allowed to free the memory yourself (Armadillo will still manage the memory).
Alternatively, you can construct an Armadillo matrix directly from existing memory. For example:
double* data = new double[4*5];
// ... fill data ...
mat X(data, 4, 5, false); // 'false' indicates that no copying is to be done; see docs
In this case you will be responsible for manually managing the memory.
Also bear in mind that Armadillo stores and accesses matrices in column-major order, ie. column 0 is first stored, then column 1, column 2, etc. This is the same as used by MATLAB, LAPACK and BLAS.
I need to modify some of the variables inside the dft function in OpenCV to make it suitable for my application.
Where can I find the dft source code?
I've tried C:\opencv243\build\include\opencv2\core.hpp but it only gives me the description of dft:
//! performs forward or inverse 1D or 2D Discrete Fourier Transformation
CV_EXPORTS_W void dft(InputArray src, OutputArray dst, int flags=0, int nonzeroRows=0);
What is the procedure after source code modification? Do I have to give it a different name such as dft2()?
Where to save the new function?
I'm using visual Studio 2010 and OpenCV 2.4.3 installed on windows7 (32 bit).
Please note that I'm new to OpenCV and just switched from MATLAB. Therefore if you are willing to help, I would be grateful if you could explain clearly.
In MATLAB I could simply right-click on the function and see the source file (for the open source functions only).
Thanks
Payam
DFT function can be found in the dxt.cpp source file. This is located in $opencv2.3$\opencv\modules\core\src
If you save it as the same function you will Overwrite that function and wont be able to use the original function. If you only want your new function then just change the code, if you want the original functionality save it as something else, dft2 would surfice but i suggest saving it as something more meaningfull like dft"whathaveIdone"
Either create some new files etc or just save it as a new function with dxt.cpp, you will need to create function definitions etc
In order to find this information I opened the OpenCV solution in Visual Studio and did a solution wide search for DFT
I want to get all distances (confidence) from predict function so I decided to change the function but my program still uses the default function (I think it reads from dlls and libs)
so how can I change a function ? Should I use cmake ? If yes how ? Please help me
Since OpenCV doesn't provide a default function, you have to create your own by creating a vector which has distance and label. You can write your own function as below and store the distance and label in the vector. Here you need to rebuild the opencv.
virtual void predict(InputArray src, int &label, double &confidence, Vector <variable>) const = 0;
I use cvBlobsLib for blob detection. At the moment I need large and small eigenvalue and corresponding eingenvectors. All what I could find in the documentation of library is CBlobGetMajorAxisLength and CBlobGetMinorAxisLength. If I am right: first gives me the large eigenvalue and the second - the small eigenvalue. But now I also need eigenvectors which I could not find in the library.
Thank you
It looks like there is a way to get the orientation angle of the blob. Rooting through the documentation (downloaded here, which is not in English, but can be understood) I found:
CBlobGetOrientation Class Reference
Public Member Functions
double operator() (const CBlob &blob) const
Aplica l'operació al blob.
const char * GetNom () const
Obté el nom de l'operador.
So, if you have the magnitude of the axis and it's orientation, you should be able to derive everything else. The only trick is, I'm not sure what the angle is referenced to.