|
it completes the execution by showing 95 percent done then an error occurs(i.e. Assertion Failed) and the marker points to the line.If i place my mouse over it shows dictionary {flag=0 dim=0 rows=0 ... }
modified 26-Feb-16 2:50am.
|
|
|
|
|
how to check featuresUnclustered contains data
|
|
|
|
|
hi Ravimal,
Below is my email id please ping me i will send you the screen shot of error that occurring
prashanthguntal@gmail.com
Thanks,
Prashanth
|
|
|
|
|
Hi,
Can you please give me the code for SVM or provide the link from where do i get that code.
Thanks,
|
|
|
|
|
SVM is there in OpenCv and we do not need to implement it. using SVM in openCV is extremely easy. We only have to provide training data, labels of training data and SVM parameters.
|
|
|
|
|
How can i change your code to work with Bag of Words with Kaze and Akaze algorithms
modified 1-Mar-16 3:49am.
|
|
|
|
|
A-KAZE uses binary descriptors by default hence we have to work in hamming space. When creating the vocabulary and populating the histogram, we have to use hamming distance instead of Euclidean distance. That is the only difference but I thing we have to implement ourself the k-means in hamming space.
|
|
|
|
|
hi,
Do you any code for akaze and kaze algorithms please send it to me
Thanks,
|
|
|
|
|
I am sorry but I don't have the codes for those algorithm. akaze is available in openCV after the version 3.0. You can directly use it for feature extraction. Just implement kmeans in hamming space, which is not hard. So you have all what you need. I will try to implement the code, but I cannot guarantee since I am in a busy schedule these days.
|
|
|
|
|
hi,
its ok thanks for your support for clearing all my doubts.If you implement it please forward it to me also.Finally Thanks You Very Much.
Thanks,
|
|
|
|
|
Hi,
Do we have to load the image in the grayscale? is there any different in the result if we load the image in the normal way as below
cv::Mat img = cv::imread(filename);
detector->detect(img, keypoint);
extractor->compute(img, keypoint, descriptor);
|
|
|
|
|
Since the feature is SIFT you should load grayscale images. In case of the color information is also important, you can use a color variant of SIFT such as Oppoenent-SIFT.
|
|
|
|
|
Hi,
do you extract the vocabulary of words from images of all the object categories of your dataset, or each object category should have its own vocabulary?
|
|
|
|
|
Vocabulary is common to the problem, not to the category. For an example, English language has a vocabulary, and an article about politics uses words from that vocabulary. We simply count the number of occurrences of words for different categories (i.e. politics, science, aesthetic, history, whether etc.)
|
|
|
|
|
Hi
How can I calculate the distance between the center of clusters obtained from Step1?
|
|
|
|
|
Distance calculation is automatically done in the BOWImgDescriptorExtractor class. However we can use Flann based matcher to rapidly find the nearest neighbors with specifying the distance calculation method.
|
|
|
|
|
Hi
I used your code for feature extraction of head tracking.
For the first step I set the image path for building dictionary to the folder containing all faces(10person*185frames), In the second step I set the path for one of dataset folders(1person=185frames). Both steps goes well(without error) except that The output of 2nd step for all frames of one person are the same vector(1*9 vector)! Is it true? So all my features for frames are the same!
|
|
|
|
|
Hi dear Ravimal Bandara
I used your code and I save the final dictionary.yml in 2nd part with this line :
FileStorage fs1("descriptor2.yml", FileStorage::APPEND);
I used APPEND because I want to save all outputs in 1 file. Dictionary.yml looks like this :
...
---
img1: !!opencv-matrix
rows: 1
cols: 9
dt: f
data: [ 8.96017700e-02, 2.14601770e-01, 9.40265507e-02,
1.02876104e-01, 1.00663714e-01, 1.01769909e-01, 6.74778745e-02,
9.62389410e-02, 1.32743359e-01 ]
...
---
img1: !!opencv-matrix
rows: 1
cols: 9
dt: f
data: [ 8.96017700e-02, 2.14601770e-01, 9.40265507e-02,
1.02876104e-01, 1.00663714e-01, 1.01769909e-01, 6.74778745e-02,
9.62389410e-02, 1.32743359e-01 ]
...
---
img1: !!opencv-matrix
rows: 1
cols: 9
dt: f
data: [ 8.96017700e-02, 2.12389380e-01, 9.51327458e-02,
1.02876104e-01, 1.01769909e-01, 1.01769909e-01, 6.74778745e-02,
9.62389410e-02, 1.32743359e-01 ]
But I just want the numbers and delete the others. for example:
[ 8.96017700e-02, 2.14601770e-01, 9.40265507e-02,1.02876104e-01, 1.00663714e-01, 1.01769909e-01, 6.74778745e-02,9.62389410e-02, 1.32743359e-01 ]
[ 8.96017700e-02, 2.14601770e-01, 9.40265507e-02,1.02876104e-01, 1.00663714e-01, 1.01769909e-01, 6.74778745e-02,9.62389410e-02, 1.32743359e-01 ]
and etc.
how can I do this?Can I save these numbers to a .csv file?(a .CSV file with #image rows*9colomns)
|
|
|
|
|
Writing in a yml file on append mode may make the file unreadable due to the corrupted format. If you need a csv then simply open a regular file and use formatted file print function.
FILE * pfile = fopen("myFile.csv","a");
for(int c=0;c<descriptor.cols;c++)
{
if(c!=(descriptor.cols-1))
fprintf(pfile,"%f,",descriptor.at<float>(0,c));
else
fprintf(pfile,"%f\n",descriptor.at<float>(0,c));
}
fclose (pfile);
|
|
|
|
|
I do not understand.
This is my code :
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/nonfree/features2d.hpp"
#include "opencv2/nonfree/nonfree.hpp"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
using namespace cv;
Mat dictionary;
SiftDescriptorExtractor Detector;
VideoCapture cap;
Mat img;
int main(int argc, char*argv[])
{
for(int i=0;i<185;i++)
{
FileStorage fs("/media/rahim/01D051E78FFCF7C0/Lab/Imageproject/BOW1out/dictionary1.yml", FileStorage::READ);
fs["vocabulary"] >> dictionary;
fs.release();
//create a nearest neighbor matcher
Ptr<descriptormatcher> matcher(new FlannBasedMatcher);
Ptr<featuredetector> detector(new SiftFeatureDetector());
Ptr<descriptorextractor> extractor(new SiftDescriptorExtractor);
//create BoF (or BoW) descriptor extractor
BOWImgDescriptorExtractor bowDE(extractor,matcher);
//Set the dictionary with the vocabulary we created in the first step
bowDE.setVocabulary(dictionary);
char * filename = new char[100];
char * imageTag = new char[10];
FileStorage fs1("descriptor2.yml", FileStorage::APPEND);
cap=VideoCapture("/media/rahim/01D051E78FFCF7C0/Lab/Dataset/EyeHead/HPEG/HPEG/session_a/videos/frame-s-a/10/%05d.jpg");
//read the image
cap >> img;
//Mat img=imread(filename,CV_LOAD_IMAGE_GRAYSCALE);
vector<keypoint> keypoints;
Detector.detect(img,keypoints);
Mat bowDescriptor;
bowDE.compute(img,keypoints,bowDescriptor);
sprintf(imageTag,"img1");
fs1 << imageTag << bowDescriptor;
fs1.release();
cout << "\n image number: " << i;
}
}
How should I use the code you said?
|
|
|
|
|
Use after
bowDE.compute(img,keypoints,bowDescriptor);
The code should be,
FILE * pfile = fopen("myFile.csv","a");
for(int c=0;c<bowDescriptor.cols;c++)
{
if(c!=(bowDescriptor.cols-1))
fprintf(pfile,"%f,",bowDescriptor.at<float>(0,c));
else
fprintf(pfile,"%f\n",bowDescriptor.at<float>(0,c));
}
bowDescriptor is what the image descriptor holds. It contains the normalized histogram of features (the bag of feature histogram). So the dimension of the content is 1 X dictionary_size . In my code it is 1 x 200
|
|
|
|
|
It works.Thanks so much
|
|
|
|
|
I used your code :
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/nonfree/features2d.hpp"
#include "opencv2/nonfree/nonfree.hpp"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
using namespace cv;
char * filename = new char[100];
Mat featuresUnclustered;
Mat descriptor;
Mat input;
SiftDescriptorExtractor detector;
int main( int argc, char** argv )
{
cv::initModule_nonfree();
cv::Mat output;
VideoCapture cap;
cap.open("/media/rahim/01D051E78FFCF7C0/Lab/Dataset/EyeHead/HPEG/HPEG/session_a/videos/faces/%05d.jpg");
for(int i=0;i<1835;i++)
{
if(i%1835==0)cap=VideoCapture("/media/rahim/01D051E78FFCF7C0/Lab/Dataset/EyeHead/HPEG/HPEG/session_a/videos/faces/%05d.jpg");//there are 335 frames in the dir
Mat frame;
std::vector<cv::keypoint> keypoints;
cap >> frame;
imshow("frame",frame);
detector.detect(frame, keypoints);
cv::drawKeypoints(frame, keypoints, output);
char *imageName = "image";
char *jpgN = ".jpg";
stringstream s;
s << imageName << i << jpgN;
cv::imwrite (s.str(), output);
detector.compute(frame, keypoints,descriptor);
featuresUnclustered.push_back(descriptor);
if(waitKey(1)==27)
exit(0);
}
//Construct BOWKMeansTrainer
//the number of bags
printf("hello");
int dictionarySize=200;
//define Term Criteria
TermCriteria tc(CV_TERMCRIT_ITER,100,0.001);
//retries number
int retries=1;
//necessary flags
int flags=KMEANS_PP_CENTERS;
//Create the BoW (or BoF) trainer
BOWKMeansTrainer bowTrainer(dictionarySize,tc,retries,flags);
//cluster the feature vectors
Mat dictionary=bowTrainer.cluster(featuresUnclustered);
//store the vocabulary
FileStorage fs("dictionary.yml", FileStorage::WRITE);
fs << "vocabulary" << dictionary;
fs.release();
return 0;
}
but this error came,what should i do?
OpenCV Error: Assertion failed (!outImage.empty()) in drawKeypoints, file /home/rahim/Desktop/OpenCV/opencv-2.4.10/modules/features2d/src/draw.cpp, line 115
terminate called after throwing an instance of 'cv::Exception'
what(): /home/rahim/Desktop/OpenCV/opencv-2.4.10/modules/features2d/src/draw.cpp:115: error: (-215) !outImage.empty() in function drawKeypoints
|
|
|
|
|
Try drawKeypoints with an initialized outimage.
frame.copyTo(outImage);
cv::drawKeypoints(frame, keypoints, output);
|
|
|
|
|
I have used your code to create a bag-of-words on ORB features. After the 1st part of the code I store the vocabulary to dictionary.yml. Then again load the vocabulary from file and compute the BOW descriptor of an image from that dictionary. But I get the following entries in the image descriptor file.
%YAML:1.0
img1: !!opencv-matrix
rows: 1
cols: 300
dt: f
data: [ 0., 0., 7.38007389e-003, 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 7.38007389e-003, 0., 3.69003695e-003, 0., 0., 0., 0.,
3.69003695e-003, 3.69003695e-003, 0., 1.47601478e-002, 0., 0., 0.,
1.47601478e-002, 3.69003695e-003, 0., 0., 0., 4.05904055e-002, 0.,
0., 0., 0., 0., 0., 3.69003695e-003, 0., 0., 3.69003695e-003,
1.47601478e-002, 0., 0., 0., 0., 0., 3.69003695e-003, 0., 0., 0.,
0., 0., 0., 0., 0., 0., 1.10701108e-002, 0., 0., 0.,
1.84501857e-002, 3.69003695e-003, 0., 0., 0., 0., 3.69003695e-003,
1.10701108e-002, 1.84501857e-002, 0., 0., 0., 0., 7.38007389e-003,
7.38007389e-003, 0., 0., 3.69003695e-003, 3.69003695e-003, 0., 0.,
3.69003695e-003, 0., 0., 1.47601478e-002, 7.38007389e-003,
3.69003695e-003, 7.38007389e-003, 0., 0., 2.58302577e-002,
3.69003695e-003, 0., 3.69003695e-003, 0., 1.10701108e-002, 0.,
3.69003713e-002, 0., 0., 3.69003695e-003, 0., 0., 0., 0., 0., 0.,
1.10701108e-002, 3.69003695e-003, 0., 7.38007389e-003, 0., 0.,
7.38007389e-003, 0., 1.10701108e-002, 0., 7.74907768e-002, 0., 0.,
0., 0., 0., 0., 0., 0., 3.69003695e-003, 0., 0., 0., 0.,
3.69003695e-003, 3.69003695e-003, 3.69003695e-003,
5.16605154e-002, 0., 3.69003695e-003, 3.69003695e-003, 0., 0., 0.,
0., 0., 3.69003695e-003, 0., 1.47601478e-002, 0., 3.69003695e-003,
7.38007389e-003, 0., 0., 0., 3.69003695e-003, 0., 0., 0.,
7.38007389e-003, 7.38007389e-003, 3.69003695e-003, 0., 0., 0., 0.,
7.38007389e-003, 7.38007389e-003, 0., 0., 0., 3.69003695e-003,
7.38007389e-003, 0., 1.84501857e-002, 3.69003695e-003,
2.21402217e-002, 0., 0., 0., 1.10701108e-002, 0., 3.69003695e-003,
0., 0., 0., 3.69003695e-003, 0., 0., 7.38007389e-003, 0., 0., 0.,
0., 0., 0., 3.69003695e-003, 0., 0., 3.69003695e-003,
3.69003695e-003, 0., 0., 3.69003695e-003, 3.69003695e-003, 0., 0.,
0., 0., 7.38007389e-003, 0., 0., 7.38007389e-003, 2.58302577e-002,
0., 0., 0., 7.38007389e-003, 0., 0., 3.69003695e-003,
3.69003695e-003, 0., 0., 3.69003695e-003, 7.38007389e-003,
3.69003695e-003, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
7.38007389e-003, 0., 0., 7.38007389e-003, 0., 0., 3.69003695e-003,
0., 0., 3.69003713e-002, 4.05904055e-002, 0., 0., 3.69003695e-003,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
1.10701108e-002, 0., 0., 1.10701108e-002, 0., 3.69003695e-003, 0.,
0., 7.38007389e-003, 0., 3.69003695e-003, 0., 0., 0., 0., 0., 0.,
3.69003695e-003, 0., 0., 0., 3.69003695e-003, 8.85608867e-002, 0.,
0., 0., 0., 0., 3.69003695e-003, 0. ]
In the file here some values are zero and others are fraction value. Is it correct output?
|
|
|
|
|