How to convert a JavaFX image to a OpenCV matrix?
<p>I am unable to successfully convert a <code>javafx.scene.image.Image</code> to a <code>org.opencv.core.Mat</code>. The resulting matrix produces a black image. I've not used <code>PixelReader</code> before so I am unsure wether or not I am using it correctly. </p>

<p>Here is my code:</p>

<pre><code>public static Mat imageToMat(Image image) {
    int width = (int) image.getWidth();
    int height = (int) image.getHeight();
    byte[] buffer = new byte[width * height * 3];

    PixelReader reader = image.getPixelReader();
    WritablePixelFormat format = WritablePixelFormat.getByteBgraInstance();
    reader.getPixels(0, 0, width, height, format, buffer, 0, 0);

    Mat mat = new Mat(height, width, CvType.CV_8UC3);
    mat.put(0, 0, buffer);
    return mat;
}
</code></pre>

<p>Any help/solutions would be greatly appreciated! :) Thank you.</p>