You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to use Java2DFrameUtils class to convert my BufferedImage to Mat but it seems the R and B channel get mixed up in certain cases and I'm not able to assert what factor comes to play since some images show up just fine while others don't. I've checked the image properties through gimp and don't seem to see any problems between the cases.
I wrote this in kotlin hope you don't mind, the images here are random ones I found laying around as well.
importorg.bytedeco.javacv.Java2DFrameUtilsimportorg.bytedeco.opencv.global.opencv_highguiimportjava.io.Fileimportjavax.imageio.ImageIOfunmain() {
val image =ImageIO.read(File("Vim Cheat Sheet.png"))
val imageMat =Java2DFrameUtils.toMat(image)
opencv_highgui.imshow("Test", imageMat)
opencv_highgui.waitKey()
}
Here's the original image:
And this is what shows up:
Another example:
This one works fine somehow
And of course
The text was updated successfully, but these errors were encountered:
You need to invert the R and B channels. To do that easily, we can set the flipChannels argument of Java2DFrameConverter.getBufferedImage() and/or Java2DFrameConverter.getFrame() to true.
As to why it sometimes happens and sometimes doesn't, that's just how ImageIO and OpenCV work. You can refer to issues #181 and #1075 for additional information about this.
I'm trying to use Java2DFrameUtils class to convert my BufferedImage to Mat but it seems the R and B channel get mixed up in certain cases and I'm not able to assert what factor comes to play since some images show up just fine while others don't. I've checked the image properties through gimp and don't seem to see any problems between the cases.
I wrote this in kotlin hope you don't mind, the images here are random ones I found laying around as well.
Here's the original image:
And this is what shows up:
Another example:
This one works fine somehow
And of course
The text was updated successfully, but these errors were encountered: