Calculating SIFT features

650 views
Skip to first unread message

Ibtissam Bouazzati

unread,
Jul 12, 2017, 10:16:29 AM7/12/17
to javacv
Hi, 

I am beginner in HIPI and the domain of image processing and I have a question about calculating an image features using sift.  For that, I use this code : 

************************** CODE : BEGIN  ****************************
// value is the Float Image
int w = value.getWidth();
int h = value.getHeight();
// conversion of floatImage to opencv Mat
Mat image = new Mat(h,w, CV_32FC3);
FloatIndexer idx = image.createIndexer();
float[] rgb = {0.0f,0.0f,0.0f};
int indice =0;

for (int i =0;i<h;i++) {
    for (int j=0;j<w;j++) {
          rgb[0] = value.getPixelArray().getElem(indice); 
          rgb[1] = value.getPixelArray().getElem(indice+1);
          rgb[2] = value.getPixelArray().getElem(indice+2);
          idx.put(i, j, 0, rgb[0]);
          idx.put(i, j, 1, rgb[1]);
          idx.put(i, j, 2, rgb[2]);
          indice = indice+3;
     }
}

// Convert the image from RGB To grayscale
cvtColor(image, image, COLOR_RGB2GRAY); 

// SIFT features
SIFT sift = new SIFT().create(); 
KeyPointVector keypoints = new KeyPointVector();
Mat descriptors = new Mat();
sift.detect(image, keypoints);
sift.compute(image,keypoints,descriptors);

****************************CODE : END ***************************
Then, I get this error :

Error: java.lang.RuntimeException: /projects/bytedeco/javacpp-presets/opencv/cppbuild/linux-x86_64/opencv_contrib-3.2.0/modules/xfeatures2d/src/sift.cpp:770: error: (-5) image is empty or has incorrect depth (!=CV_8U) in function detectAndCompute
at org.bytedeco.javacpp.opencv_features2d$Feature2D.detect(Native Method)
at org.hipi.examples.Hbasefeatures$FeaturesMapper.map(Hbasefeatures.java:185)
at org.hipi.examples.Hbasefeatures$FeaturesMapper.map(Hbasefeatures.java:63)
at org.apache.hadoop.mapreduce.Mapper.run(Mapper.java:146)
at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:787)
at org.apache.hadoop.mapred.MapTask.run(MapTask.java:341)
at org.apache.hadoop.mapred.YarnChild$2.run(YarnChild.java:164)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:422)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1698)
at org.apache.hadoop.mapred.YarnChild.main(YarnChild.java:158)

From the error, I think that the problem is that the type of opencv Mat that I give to the detect and compute methods is not the right one.

Can you tell me please if the image conversion from RGB to Grayscale isn't right ? 
Have you any idea about how  this opencv Mat passed to thoses methods should be ? 

Samuel Audet

unread,
Jul 12, 2017, 6:51:19 PM7/12/17
to javacv
It's just saying that you need an CV_8UC3 image instead of CV_32FC3. We can use Mat.convertTo() for that. 

Samuel

2017/07/12 23:16 "Ibtissam Bouazzati" <bouazzati...@gmail.com>:

--

---
You received this message because you are subscribed to the Google Groups "javacv" group.
To unsubscribe from this group and stop receiving emails from it, send an email to javacv+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ibtissam Bouazzati

unread,
Jul 20, 2017, 8:19:16 AM7/20/17
to javacv
Exactly, it works ! Thank you for your answer 
Samuel

To unsubscribe from this group and stop receiving emails from it, send an email to javacv+un...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages