本文整理汇总了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()));
}