本文整理匯總了Java中org.opencv.imgcodecs.Imgcodecs.imencode方法的典型用法代碼示例。如果您正苦於以下問題:Java Imgcodecs.imencode方法的具體用法?Java Imgcodecs.imencode怎麽用?Java Imgcodecs.imencode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.opencv.imgcodecs.Imgcodecs
的用法示例。
在下文中一共展示了Imgcodecs.imencode方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: showResult
import org.opencv.imgcodecs.Imgcodecs; //導入方法依賴的package包/類
public void showResult(Mat img) {
Imgproc.resize(img, img, new Size(640, 480));
MatOfByte matOfByte = new MatOfByte();
Imgcodecs.imencode(".jpg", img, matOfByte);
byte[] byteArray = matOfByte.toArray();
BufferedImage bufImage = null;
try {
InputStream in = new ByteArrayInputStream(byteArray);
bufImage = ImageIO.read(in);
JFrame frame = new JFrame();
frame.getContentPane().add(new JLabel(new ImageIcon(bufImage)));
frame.pack();
frame.setVisible(true);
} catch (IOException | HeadlessException e) {
e.printStackTrace();
}
}
示例2: getData
import org.opencv.imgcodecs.Imgcodecs; //導入方法依賴的package包/類
@Override
public byte[] getData() {
Mat m = dequeue();
if(m == null)
return null;
Imgcodecs.imencode(".jpg", m, buffer, compressParams);
byte[] imageArr = new byte[(int) (buffer.total() * buffer.elemSize())];
buffer.get(0, 0, imageArr);
return imageArr;
}
示例3: mat2Image
import org.opencv.imgcodecs.Imgcodecs; //導入方法依賴的package包/類
/**
* Convert a Mat object (OpenCV) in the corresponding Image for JavaFX
*
* @param frame
* the {@link Mat} representing the current frame
* @return the {@link Image} to show
*/
private Image mat2Image(Mat frame)
{
// create a temporary buffer
MatOfByte buffer = new MatOfByte();
// encode the frame in the buffer, according to the PNG format
Imgcodecs.imencode(".png", frame, buffer);
// build and return an Image created from the image encoded in the
// buffer
return new Image(new ByteArrayInputStream(buffer.toArray()));
}
示例4: getData
import org.opencv.imgcodecs.Imgcodecs; //導入方法依賴的package包/類
/**
* {@inheritDoc}
* <p>
* Compresses the frame into a .jpg.
* </p>
*/
@Override
public byte[] getData() {
if(read() == null) return null;
Imgcodecs.imencode(".jpg", image, buffer, compressParams);
byte[] imageArr = new byte[(int) (buffer.total() * buffer.elemSize())];
buffer.get(0, 0, imageArr);
return imageArr;
}
示例5: getData
import org.opencv.imgcodecs.Imgcodecs; //導入方法依賴的package包/類
/**
* {@inheritDoc}
* <p>
* Compresses the frame into a .jpg.
* </p>
*/
@Override
public byte[] getData() {
if(!capture.isOpened()) return null;
if(read() == null) return null;
Imgcodecs.imencode(".jpg", image, buffer, compressParams);
byte[] imageArr = new byte[(int) (buffer.total() * buffer.elemSize())];
buffer.get(0, 0, imageArr);
return imageArr;
}
示例6: cvMat2FxImage
import org.opencv.imgcodecs.Imgcodecs; //導入方法依賴的package包/類
public static Image cvMat2FxImage(Mat mat){
MatOfByte buffer = new MatOfByte();
Imgcodecs.imencode(".png", mat, buffer);
return new Image(new ByteArrayInputStream(buffer.toArray()));
}
示例7: getImage
import org.opencv.imgcodecs.Imgcodecs; //導入方法依賴的package包/類
public static BufferedImage getImage(Mat matrix) throws IOException {
MatOfByte mob = new MatOfByte();
Imgcodecs.imencode(".jpg", matrix, mob);
return ImageIO.read(new ByteArrayInputStream(mob.toArray()));
}