I'm using the below code to get an image from the camera, but the camera image shows colours differently.
public Mat mat = new Mat();
private BufferedImage img;
private byte[] dat;
    public void getSpace(Mat mat) {
            this.mat = mat;
            int w = mat.cols(), h = mat.rows();
            if (dat == null || dat.length != w * h * 3)
                dat = new byte[w * h * 3];
            if (img == null || img.getWidth() != w || img.getHeight() != h || img.getType() != BufferedImage.TYPE_3BYTE_BGR)
                img = new BufferedImage(w, h, BufferedImage.TYPE_3BYTE_BGR);
        }
        public BufferedImage getImage(Mat mat) {
            getSpace(mat);
            mat.get(0, 0, dat);
            img.getRaster().setDataElements(0, 0, mat.cols(), mat.rows(), dat);
            return img;
        }
