OpenImaj and OpenCV - SURF feature descriptor to byte array

647 views Asked by At

For reasons I won't go into, I'm needing to convert the SURF feature descriptors extracted from an image, which are stored in a Mat object, to a byte[] which is the format OpenImaj keypoints store the keypoint descriptors in. Am I going about this the right way?

public LocalFeatureList<Keypoint> findFeatures(FImage image) {
    BufferedImage bimg = ImageUtilities.createBufferedImage(image);
     byte[] pixelsfalt = ((DataBufferByte)     bimg.getRaster().getDataBuffer()).getData();

    Mat matimage = new Mat(bimg.getWidth(),bimg.getHeight(),CvType.CV_8UC(1));
    matimage.put(0, 0, pixelsfalt);

    MatOfKeyPoint keypoints = new MatOfKeyPoint();
    Mat descriptor = new Mat();

    fd.detect(matimage, keypoints);
    surfExtractor.compute(matimage, keypoints, descriptor);

    //this is wrong as far as I know
    float [] desc = new float[descriptor.height()*descriptor.width()];
    descriptor.get(0,0,desc);

    LocalFeatureList<Keypoint> toReturn = new MemoryLocalFeatureList<Keypoint>();
    org.opencv.features2d.KeyPoint[] matkeys = keypoints.toArray();


    for(org.opencv.features2d.KeyPoint k : matkeys){

        Keypoint toAdd = new Keypoint();
        toAdd.x = (float) k.pt.x;
        toAdd.y = (float) k.pt.y;

        toAdd.scale = k.size;
        toAdd.ori = (float) Math.toRadians(k.angle);
        //so is this
        toAdd.ivec = new byte[128];
        toReturn.add(toAdd);
    }

    return toReturn;
}
0

There are 0 answers