Load Image OpenCV (JavaCV) from byte[] not a file
Question
I have image data coming in from over a socket connection as a byte[]. All examples I have seen using cvLoadImage()
is passed a file name. Do I have to save every image to file and re-open it to do the processing? This seems to have a lot of overhead for what needs to happen, is it possible to load the image from the byte[] data?
Solution 2
Simple solution in the end, you can use the following method to create an Image from a BufferedImage which solved my problem:
IplImage src = IplImage.createFrom(buffered);
OTHER TIPS
Assuming the data is encoded in some standard format like JPG or PNG, and assuming you are using JavaCV, for a byte array b, this works as well:
IplImage image = cvDecodeImage(cvMat(1, b.length, CV_8UC1, new BytePointer(b)));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow