Ask Your Question

tuannhtn's profile - activity

2017-08-31 00:15:54 -0600 received badge  Nice Answer (source)
2017-02-27 16:55:22 -0600 received badge  Good Answer (source)
2016-07-27 21:00:54 -0600 commented question Install OpenCV from source using Visual Studio 2015

Your cmake is too old (2.8) while opencv and vs are new. This may cause a lot of errors. You should update cmake to its latest version and try again.

2016-07-26 20:09:22 -0600 answered a question Mat and imread memory management

There are some problems with your code:

  1. If you want to read a lot of images, do not use their names as command line arguments. Instead, put their names into a file and use that file name as one argument. Thus, your command line is shorter and neater and this helps to avoid the limitation of the number of command line arguments for a program.
  2. If your put a local Mat into an outside vector<mat>, you have to remove the img.release() statement since it frees the memory for the object that is being managed by the vector. Or, in case you keep the img.release() statement, you have to put each clone of one read image.
  3. If your images are of the same size and you know their number, you should initiate a vector<mat> using those parameters such as: vector<mat> imagesArg(300, cv::Mat(128, 128, CV_8U)); and then you can read each image as: imagesArg[i] = imread(imgNames[i], 0);

In fact, 300 images are not huge with a program and the idea of keeping images in a vector is not a good approach. You'd better read each image, process it, then store the results of all the images in a vector.

2016-06-28 09:57:50 -0600 answered a question vector Mat crashes

You should take care of the scope of hist object, if it is outside the first loop, then your will obtain errors since your Histograms vector will contains references to one hist object. It must be one local Mat object or you have to push_back its clone, not the reference to it (in this case, the name - hist). Below is the wrong code:

    vector<cv::Mat> hists;
    vector<string> files = { "1.pgm", "2.pgm", "4.pgm" };
    int histSize = 256;

    float range[] = { 0, 256 };
    const float* histRange = { range };

    bool uniform = true; bool accumulate = false;
    Mat img;
    Mat hist;
    for (int i = 0; i < files.size(); i++)
    {
        img = cv::imread(files[i], 0);
        cv::calcHist(&img, 1, 0, Mat(), hist, 1, &histSize, &histRange, uniform, accumulate);
        hists.push_back(hist);
    }
    for (int i = 0; i < files.size(); i++)
    {
        cout << hists[i].rows << endl;
        cout << hists[i].t() << endl;
    }

And the two versions hereafter are correct:

    Mat img;
    for (int i = 0; i < files.size(); i++)
    {
        Mat hist;
        img = cv::imread(files[i], 0);
        cv::calcHist(&img, 1, 0, Mat(), hist, 1, &histSize, &histRange, uniform, accumulate);
        hists.push_back(hist);
    }
    for (int i = 0; i < files.size(); i++)
    {
        cout << hists[i].rows << endl;
        cout << hists[i].t() << endl;
    }

Or:

    Mat img;
    Mat hist;
    for (int i = 0; i < files.size(); i++)
    {
        img = cv::imread(files[i], 0);
        cv::calcHist(&img, 1, 0, Mat(), hist, 1, &histSize, &histRange, uniform, accumulate);
        hists.push_back(hist.clone());
    }
    for (int i = 0; i < files.size(); i++)
    {
        cout << hists[i].rows << endl;
        cout << hists[i].t() << endl;
    }
2016-06-27 05:22:45 -0600 commented answer Opencv and TBB in image processing

AFAIK, all the statements after the join() call can deal with results obtained from previous threads (whose join() were called). So if you fed image (s) to one thread to process, after its join() finishes (join() statement in the program), you can be sure to cope with other images (or the ones produced from the thread).

2016-06-27 05:15:10 -0600 commented answer OpenCV 3.1 x64 libs for visual studio 2015

I built OpenCV 3.1 (latest source from github) with VS 2015 update 2 on Windows 7 SP1 64 bit and had no error. TBB and Eigen were also used.

2016-05-20 02:24:05 -0600 commented answer What image format is best use for facial recognition?

I think the resolution should depend on the method you use but generally (from the literature and my experience) the 128x128 resolution is sufficient.

2016-05-18 23:41:03 -0600 answered a question What image format is best use for facial recognition?

They are the same. As a facial recognition method uses intensity values read from images for performing the recognition process, the format does not affect the results. But the format will affect when saving images from acquisition devices, the quality of the pictures may reduce if you use compressed format such as jpg.

2016-05-18 09:50:35 -0600 answered a question building error: opencv3.1 with VS2015, 64-bit, CMake 3.5.2

Because the OpenCV solution was not built. The INSTALL project can be built only after other projects are compiled. To solve this, you have to choose Project menu item, then Build Solution (or just press F7) and wait until all projects are compiled. After that, if there is no error, just choose the INSTALL project and Build Only it to have .lib and .dll files for using with your applications.

2016-05-16 10:17:32 -0600 answered a question gender detection, simple question

IMHO, the tutorial's goal is to provide you a sample that can work. It is not a solution for any real life application. However, to make it achieve as higher result as possible, you should:

  1. Use training images that have the same conditions (light, outdoor conditions, etc.) as the test images your application will manipulate.
  2. It is not cheating. To recognize any kind of object (in this case, gender), your application must base on some model which is derived from correct training data and this mechanism is similar to our brain. This is actual prediction.
2016-05-13 22:05:07 -0600 answered a question Accessing each pixel of a Mat .at vs pointer arithmetic gives differnet result

You have to change the line:

 uint8_t* p = y_channel.data;

to:

float * p = (float*)y_channel.data;

and no need to use saturate_cast<>, just do like this:

std::cout << p[i*y_channel.cols + j] << std::endl;
2016-03-19 08:20:50 -0600 received badge  Nice Answer (source)
2016-03-17 20:45:51 -0600 commented question Apply function to each Mat element

Agree with @LorenaGdL about using basic matrix operations which are optimized by SSE, AVX codes and other parallel techniques (if needed). Your code should be:

void calcDepthValues(const Mat &depth, Mat & realDepth){ // should not return a Mat, it can be a very huge object
        realDepth= depth.clone();
        float a = -10758.02914f/255; // fix it if you already knew it 
        float b = 448.251214f+10758.02914f; // fix it if you already knew it

        realDepth *= a;
        realDepth += b;
    }
2016-03-17 04:33:06 -0600 answered a question Copy histogram of an image to another

I think this source is a sample you may want.

2016-03-10 04:03:53 -0600 answered a question Is there any way to decrease CPU usage of feature detector?

Try this:

#include <tbb\task_scheduler_init.h>

tbb::task_scheduler_init init(1);
2016-03-09 18:52:29 -0600 answered a question Issue with calcHist

You have to change your numDims from 8 to 3.

2016-02-01 07:55:23 -0600 commented question Build a tracker with open cv,clapack and visual studio 2015

@anony, can you provide some code so I can reproduce your problem?

2016-02-01 07:00:38 -0600 commented question Build a tracker with open cv,clapack and visual studio 2015

I have some experience with lapack when using it with OpenCV. In fact, you don't have to recompile the clapack project, just adding some external declarations of the functions you used in your program. In my case, I compiled lapack with GCC (using msys and mingw on Windows) and then used it with OpenCV in Visual Studio.

2016-02-01 04:57:41 -0600 commented question Build a tracker with open cv,clapack and visual studio 2015

Did you write an extern "C" declaration for the functions (from lapack) you used in your program, such as:

extern "C" void dpotrf_(char *uplo,int *jb,double *A,int *lda,int *info);
2016-01-05 10:30:08 -0600 answered a question OpenCV 3.1 x64 libs for visual studio 2015

The answer is simple: just build it yourself. From my experience, there is no difference in building Opencv 3.1 x64 and that of Opencv 3.0 with VS 2015. But since I encountered errors with VS 2015 RTM, you should upgrade to VS 2015 update 1 before doing that. Good luck.

2015-12-09 19:33:49 -0600 commented answer VS 2015 internal error C1001 building the latest 3.0.0-dev release

Yes, v140, and I have tested with both SSE and AVX options (1st test with SSE only, 2nd test with AVX enable).

2015-12-09 09:35:16 -0600 commented answer VS 2015 internal error C1001 building the latest 3.0.0-dev release

VS 2015 enterprise with Update 1.

2015-12-09 09:17:33 -0600 commented answer VS 2015 internal error C1001 building the latest 3.0.0-dev release

I do not know what version of VS you use. But I still succeeded when building OpenCV 3 (latest dev version from github with IPP 9 and TBB 4.4 Update 1) in debug mode.

2015-12-07 00:18:42 -0600 commented answer Running 2 algorithms simulatenously

Can you give the detailed code?

2015-12-02 07:35:23 -0600 answered a question VS 2015 internal error C1001 building the latest 3.0.0-dev release

Today, after installing Update 1 of VS 2015, I have successfully built OpenCV 3.0-dev 64 bit (latest source code from github). So the internal compiler error was caused by a VS 2015 RTM's bug. Hope this help some one who wants to try OpenCV 3.0 with VS 2015.

2015-11-25 07:20:43 -0600 answered a question overfitting when training SVM for gender classfication

@StevenPuttemans, I still keep my opinion, it comes from my experience with gender classification problem. Of course, you example is right, but innately, within the threshold, the accuracy should be better. @CurtisFu, your images are fairly small, you should try with at least 64x64 resolution images. I have tested with polynomial kernel function and LBP features on LFW database (over 12000 images) and the average recognition rate (cross validation test with 1/5 database for test set while the rest-4/5 for training) was above 90%.

2015-11-25 03:54:08 -0600 commented question overfitting when training SVM for gender classfication

Yes, @StevenPuttemans, increasing training set's size does not always lead to improvement in accuracy: there is a threshold of this number so that even when you add more images to the training set, the accuracy does not improve. But it is usually do, before you reach the threshold.

2015-11-25 00:34:38 -0600 commented question overfitting when training SVM for gender classfication

AFAIK, when there are more images for training, the accuracy performance should be better. To improve the recognition rate, you can try other advanced feature extraction methods, for example Local Phase Quantization (LPQ), or combine several methods together. To pinpoint why you get lower classification rate with more training images, you should provide more information: your code, your parameters' settings and your experimental images.

2015-11-14 08:20:37 -0600 commented question VS 2015 internal error C1001 building the latest 3.0.0-dev release

Can you give the full list of that 8 errors?

2015-11-14 02:04:00 -0600 commented question VS 2015 internal error C1001 building the latest 3.0.0-dev release

I have encountered the same problem and now I have to use VS 2015 with OpenCV 3 compiled by VS 2013 and some code issue errors, for example ORB, SIFT and SURF feature detections.

2015-11-08 11:24:56 -0600 commented answer Is OpenCv 3.0 compatible for VS 2015

I put opencv and opencv_contrib into the folder F:\lib and build (from F:\lib\opencv\dyn2015) and encoutered following errors:

1>------ Build started: Project: ZERO_CHECK, Configuration: Release x64 ------
2>------ Skipped Build: Project: RUN_TESTS, Configuration: Release x64 ------
2>Project not selected to build for this solution configuration 
1>  Checking Build System
1>  The system cannot find the path specified.
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(171,5): error MSB6006: "cmd.exe" exited with code 3.
3>------ Build started: Project: opencv_hal, Configuration: Release x64 ------
4>------ Build started: Project: zlib, Configuration: Release x64 ------
5>------ Build started: Project: libjasper, Configuration: Release x64 ------
6>------ B
2015-11-08 10:47:36 -0600 commented answer Is OpenCv 3.0 compatible for VS 2015

Thanks @LBerger, I will check and let you know the results.

2015-11-08 08:29:32 -0600 commented answer Is OpenCv 3.0 compatible for VS 2015

Thanks @LBerger, the error was: INTERNAL COMPILER ERROR: fatal error C1001 (compiler file '...\vctools\compiler\utc\src\p2\main.c', line 246). I checked your configuration details and they are the same as mine. If possible, could you compress and send your full worled solution to me via email?

2015-11-08 05:47:00 -0600 commented answer Is OpenCv 3.0 compatible for VS 2015

I tried to disable both /O2 and precompiled headers options but the errors still remained. I post my configurations here so some one can suggest a solution:

General configuration for OpenCV 3.0.0-dev =====================================
  Version control:               unknown

  Platform:
    Host:                        Windows 6.1 AMD64
    CMake:                       3.3.2
    CMake generator:             Visual Studio 14 2015 Win64
    CMake build tool:            C:/Program Files (x86)/MSBuild/14.0/bin/MSBuild.exe
    MSVC:                        1900

  C/C++:
    Built as dynamic libs?:      YES
    C++ Compiler:                C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe  (ver 19.0.23026.0)
    C++ flags (Release):         /DWIN32 /D_WINDOWS /W4 /G
2015-11-07 22:10:37 -0600 received badge  Necromancer (source)
2015-11-07 21:33:54 -0600 answered a question Is OpenCv 3.0 compatible for VS 2015

After trying to build OpenCV 3.0 from source (fresh download from https://github.com/Itseez/opencv) by both VS 2015 Professional and Enterprise editions on a Win 7 64 bit machine, my conclusion is: currently, OpenCV 3.0 can not be built with VS 2015 due to an ICE: https://connect.microsoft.com/VisualS.... Hope VS 2015 update 1 can rectify this problem.

2015-11-07 15:24:02 -0600 received badge  Nice Answer (source)
2015-11-06 19:03:51 -0600 answered a question How to implement a butterworth filter in OpenCV
2015-10-26 22:35:26 -0600 commented answer Running 2 algorithms simulatenously

From my experience, I suggest you the Threading Building Blocks (TBB) from Intel.

2015-10-26 09:06:27 -0600 commented answer Running 2 algorithms simulatenously

Thanks @pklab, I am indeed aware of that. The code is ok because two threads are independent (only src is common, but it is read only accessed) and there is no race condition. As you emphasized, this situation was very simple, and more complicated contexts will need other tools to control accessing to common data.

2015-10-25 12:21:14 -0600 received badge  Nice Answer (source)