5

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?

SamRowley
  • 3,435
  • 7
  • 48
  • 77

2 Answers2

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);
SamRowley
  • 3,435
  • 7
  • 48
  • 77
2

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)));

Samuel Audet
  • 4,964
  • 1
  • 26
  • 33