Ask Your Question

RossFe92's profile - activity

2017-01-28 05:03:07 -0600 commented answer How to calculate labels given centers of K-Means in OpenCV

Can you suggest me how to do this in c++? Thanks.

2017-01-28 04:51:41 -0600 received badge  Editor (source)
2017-01-28 04:27:55 -0600 asked a question How to calculate labels given centers of K-Means in OpenCV

Hello, I read this question about how to set initial centers of k-mean on Stackoverflow. I read the answer, but I have no idea how to implement it in C ++. Could anyone give me any suggestions? I'd like to calculate first labels using centers that I already have and pass them to kmeans function with flag KMEANS_USE_INITIAL_LABELS for calculate new centers on new (but similar) data. Data are features of images.

2017-01-25 10:00:08 -0600 asked a question VLFeat K-means: how to use in c++

I've read of VLFeat, which has an implementation of the algorithm of k-mean, which is faster than that of OpenCV, but do not understand how to readjust this code (in c++ and OpenCV) to use VLFeat.

Mat rawFeaturesData; // mat with images dataset features  
...
Mat labels, centers;
int bin_size = 1000;
kmeans(rawFeatureData, bin_size, labels, TermCriteria( TermCriteria::COUNT+TermCriteria::EPS, 100, 1.0),
       3, KMEANS_PP_CENTERS, centers);

Could someone tell me how to do? Thank you.

2017-01-21 05:16:31 -0600 commented answer Trimap image use in OpenCV

I had already read, how should I edit the berak's answer then?

2017-01-21 04:56:58 -0600 commented answer Trimap image use in OpenCV

Unfortunately neither the image, the trimap and mask are empty and all three have the same size (600x400)...

2017-01-21 04:43:22 -0600 commented answer Trimap image use in OpenCV

Thanks for your answer. I've tried but I've this error:

OpenCV Error: Assertion failed (mask.empty() || (mask.type() == CV_8U && size == mask.size)) in setTo, file /opt/OpenCV/opencv-3.0.0/modules/core/src/copy.cpp, line 473
terminate called after throwing an instance of 'cv::Exception'
  what():  /opt/OpenCV/opencv-3.0.0/modules/core/src/copy.cpp:473: error: (-215) mask.empty() || (mask.type() == CV_8U && size == mask.size) in function setTo
2017-01-21 04:18:04 -0600 commented answer Trimap image use in OpenCV

How then I can use it to get a picture with the cat or dog on a black background?

2017-01-21 03:18:29 -0600 asked a question Trimap image use in OpenCV

Hello, I found The Oxford-IIIT Pet Dataset, which contains images of dogs and cats. For each image has a pixel level foreground-background segmentation (trimap) image. Searching the internet, I saw that trimap is an image with three colors (one for the background, one for the foreground and one for the not-classified region), but here the image is all black. It's a mistake or is correct so too? But above all I want to know if and how you can use it to get, given a normal image, a new image with the cat or dog on a black background. Thanks.

2017-01-16 11:04:35 -0600 received badge  Enthusiast
2017-01-13 09:55:49 -0600 commented answer Reduce SURF descriptor size in Opencv

This is the code:

Mat eigenvalues, eigenvectors, mean, projection_features;
    PCA pca;

    FileStorage fs(input_file2, FileStorage::READ);
    fs["pca_mean"] >> mean;
    fs["pca_eigenvalues"] >> eigenvectors;
    fs["pca_eigenvectors"] >> eigenvalues;
    fs.release();

    pca.mean = mean;
    pca.eigenvalues = eigenvalues;
    pca.eigenvectors = eigenvectors; 
    pca.project(features, projection_features);
2017-01-13 09:34:56 -0600 commented answer Reduce SURF descriptor size in Opencv

I have load PCA but now I have this error:

OpenCV Error: Assertion failed (!mean.empty() && !eigenvectors.empty() && ((mean.rows == 1 && mean.cols == data.cols) || (mean.cols == 1 && mean.rows == data.rows))) in project, file /opt/OpenCV/opencv-3.0.0/modules/core/src/pca.cpp, line 296
terminate called after throwing an instance of 'cv::Exception'
  what():  /opt/OpenCV/opencv-3.0.0/modules/core/src/pca.cpp:296: error: (-215) !mean.empty() && !eigenvectors.empty() && ((mean.rows == 1 && mean.cols == data.cols) || (mean.cols == 1 && mean.rows == data.rows)) in function project

Data (features) is [64x988] while PCA mean is [200x1]...

2017-01-13 03:22:26 -0600 commented answer Reduce SURF descriptor size in Opencv

Forgive me but it is only recently that use opencv. I have to use the pca previously created (in features_extraction.cpp) on this image and extract features with dense surf (on this or the whole dataset)?

2017-01-13 02:53:57 -0600 commented answer Reduce SURF descriptor size in Opencv

The code I mentioned above is not for the training part (I modified appropriately train.cpp file for that). It is just to test later image alien to the dataset.

2017-01-12 13:01:50 -0600 commented question Reduce SURF descriptor size in Opencv

I've modified come from https://github.com/OpenCVBlueprints/OpenCVBlueprints/tree/master/chapter_3 (link text) for recognize dogs instead of facial expression. What can I test this for a different image (I would like that date the image of a labrador, it returns me "labrador").

2017-01-12 12:19:03 -0600 asked a question Reduce SURF descriptor size in Opencv

Hi, I want to resize SURF descriptor for pass it to SVM predict function (SVM was previously trained on an images dataset). My descriptor is [64x988] and I'd like it to become [124x1]. I try this:

    Mat features = extractFeature(img_gray);
    features = features.reshape(1,1);

    Mat projection_features;
    PCA pca(features, Mat(),CV_PCA_DATA_AS_ROW, 124); 
    pca.project(features,projection_features);

    Ptr<ml::SVM> svm = ml::SVM::create();
    svm = ml::SVM::load<ml::SVM>(input_file);
    float result = svm->predict(projection_features);

but I have now a [1x1] matrix. My extract features function is:

Mat extractFeature(Mat img)
{
    Mat descriptors;
    vector<KeyPoint> keypoints;

    Ptr<Feature2D> surf = xfeatures2d::SURF::create();
    surf->detect(img, keypoints, Mat());
    surf->compute(img, keypoints, descriptors);

    return descriptors;
}

Where's the problem? Otherwise, there are other ways to reduce descriptor's size or for directly obtain a descriptor of that size? Thanks.

2016-12-19 09:06:16 -0600 commented question OpenCV By Example book code error

The code that I reported were impeding compilation. I settled with the substitution made above. Now I have this error when I run the program but do not know where to search for it. I can not mention all the code because it is long (you can download at link - sorry for this).

2016-12-19 07:49:04 -0600 asked a question OpenCV By Example book code error

Hello, I downloaded the examples of the book "OpenCV By Example" link text and I run the code in Chapter 6. The compilation (according to the readme file) is successful after replacing:

 // Set up SVM's parameters
  SVM::Params params;
  params.svmType    = SVM::C_SVC;
  params.kernelType = SVM::CHI2;
  params.termCrit   = TermCriteria(TermCriteria::MAX_ITER, 100, 1e-6);

  // Train the SVM
  svm = StatModel::train<SVM>(trainingDataMat, ROW_SAMPLE, responses, params);

with this:

  // Set up SVM's parameters
  svm = SVM::create();
  svm->setType(SVM::C_SVC);
  svm->setKernel(SVM::CHI2);
  svm->setTermCriteria(TermCriteria(TermCriteria::MAX_ITER, 100, 1e-6));

  // Train the SVM
  svm->train(trainingDataMat, ROW_SAMPLE, responses);

But when I try to run the program I get this:

init done
opengl support available
OpenCV Error: Sizes of input arguments do not match (The operation is neither 'array op array' (where arrays have the same size and the same number of channels), nor 'array op scalar', nor 'scalar op array') in arithm_op, file /opt/opencv-3.1.0/modules/core/src/arithm.cpp, line 639
terminate called after throwing an instance of 'cv::Exception'
  what():  /opt/opencv-3.1.0/modules/core/src/arithm.cpp:639: error: (-209) The operation is neither 'array op array' (where arrays have the same size and the same number of channels), nor 'array op scalar', nor 'scalar op array' in function arithm_op

I have opencv 3.0 (I also tried it with opencv 3.1)

How can I fix the problem? Thanks