|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools |
Rating:
|
Display Modes |
|
|
|
#1
|
|||
|
|||
|
Re: OpenCV USBCamera convert to Mat
I don't believe this is the typical way of converting a Mat to a BufferedImage. From my experience it is much similar to use MatOfByte:
Code:
// Lots of code... Mat mat = getSomeImageMat(); MatOfByte bytes = new MatOfByte(); Highgui.imencode(someFormat, mat, bytes); byte[] arr = bytes.toArray(); ByteArrayInputStream bis = new ByteArrayInputStream(arr); BufferedImage img = ImageIO.read(bis); // Even more code... // Exceptions and Stream Closing omitted for brevity (I noticed you used this algorithm, but I will leave it here for future reference) http://stackoverflow.com/questions/1...-mat-in-opencv Is there some limitation where you can't use MatOfByte? Last edited by MatthewC529 : 29-01-2015 at 21:25. Reason: Me Being Overzealous with Solutions :) |
|
#2
|
||||
|
||||
|
Re: OpenCV USBCamera convert to Mat
I attached a screenshot of how the images come out with my current method after converting from BufferedImage to Mat, im going to try with the MatOfBte Method and see if that works, thanks for the help
|
|
#3
|
||||
|
||||
|
Re: OpenCV USBCamera convert to Mat
No, there is no limitation where we cant use MatOfByte, but i don't believe the issue lies in that part of the code, i can convert a Mat to a BufferedImage without any problems... the problem comes in when I try to take the image from the usb camera, which comes in as a BufferedImage, and convert it to a Mat.
|
|
#4
|
||||
|
||||
|
Re: OpenCV USBCamera convert to Mat
For whatever reason, switching the Mat Declaration to the one shown seemed to fix the problem, for anyone who finds this in the future.
Code:
public static Mat bufferedImageToMat(BufferedImage i) {
byte[] pixels = ((DataBufferByte) i.getRaster().getDataBuffer()).getData();
Mat img = new Mat();
img = new Mat(new Size(i.getWidth(), i.getHeight()), CvType.CV_8UC3);
img.put(0, 0, pixels);
return img;
}
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|