Ask Your Question

joseFraunhofer's profile - activity

2013-03-07 07:25:52 -0600 received badge  Supporter (source)
2013-03-07 07:24:25 -0600 commented answer Convert Mat to MatOfByte in Android

At least!! something that works! you have saved my project! You must be the Chuck Norris's son! XD

2013-03-07 05:03:11 -0600 commented answer Mat to byte array

sorry, I couldn't write all

public int safeLongToInt(long l) {
    if (l < Integer.MIN_VALUE || l > Integer.MAX_VALUE) {
        throw new IllegalArgumentException
            (l + " cannot be cast to int without changing its value.");
    }
    return (int) l;
}
2013-03-07 05:01:13 -0600 commented answer Mat to byte array

Hi! I am trying to do the same conversion in java desktop with opencv 2.4.4. I want to transform the Mat data in byte array to create ImageIcon to display in JLabel. I tried this, but it doesn't work..

Mat image = new Mat(); VideoCapture camCapture = new VideoCapture(0); //then I read the capture from the camera camCapture.read(frame)

//I know that the type of mat is CV_8UC3 continuous so, I try to use that functions

public ImageIcon getImageIconFromMatTo(Mat frame){
    ImageIcon retImage = null;
    byte[] imageInBytes = new byte[(safeLongToInt(frame.total())) * frame.channels()];
    frame.get(0, 0, imageInBytes);

    retImage = new ImageIcon(imageInBytes);

    return retImage;
}

public int safeLongToInt(long l) {
    if (l < Integer.MIN_VALUE || l > Integer.MAX_VALU

help please!