本文整理汇总了Java中org.opencv.highgui.Highgui.imwrite方法的典型用法代码示例。如果您正苦于以下问题:Java Highgui.imwrite方法的具体用法?Java Highgui.imwrite怎么用?Java Highgui.imwrite使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.opencv.highgui.Highgui
的用法示例。
在下文中一共展示了Highgui.imwrite方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: btnTomarFotoActionPerformed
import org.opencv.highgui.Highgui; //导入方法依赖的package包/类
private void btnTomarFotoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTomarFotoActionPerformed
// TODO add your handling code here:
FileNameExtensionFilter filtro = new FileNameExtensionFilter("Formatos de Archivo JPEG(*.JPG;*.JPEG)","jpg","jpeg");
jFileChooser1.addChoosableFileFilter(filtro);
jFileChooser1.setFileFilter(filtro);
File Nombre =new File(txtNombre.getText()+" "+txtApellido.getText()+".jpg");
jFileChooser1.setSelectedFile(Nombre);
jFileChooser1.setDialogTitle("Guardar Imagen");
File ruta = new File("C:/Imagenes");
jFileChooser1.setCurrentDirectory(ruta);
int returnVal = jFileChooser1.showSaveDialog(null);
if (returnVal == jFileChooser1.APPROVE_OPTION) {
File file = jFileChooser1.getSelectedFile();
Highgui.imwrite(file.getPath(), frame);
} else {
System.out.println("File access cancelled by user.");
}
}
示例2: main
import org.opencv.highgui.Highgui; //导入方法依赖的package包/类
/**
* Command-line interface.
*
* <p>This example tests the OpenCV installation
* and takes a picture with this OpenCV tool.</p>
*
* @param args unused here.
*/
public static void main(String[] args) {
// Load the native library.
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
Tools.log(Core.NATIVE_LIBRARY_NAME);
VideoCapture camera = new VideoCapture(0);
Tools.sleepMilliseconds(1000);
if(!camera.isOpened())
Tools.log("Video capturing hasn't been correctly initialized.");
else
Tools.log("The camera has been correctly initialized.");
Mat frame = new Mat();
camera.read(frame);
Highgui.imwrite("capture.jpg", frame);
}
示例3: main
import org.opencv.highgui.Highgui; //导入方法依赖的package包/类
public static void main(String[] args) {
// ָ��������ͼƬ·����������ļ�
String inputImagePath = identificate.class.getClassLoader().getResource("hf.jpg").getPath().substring(1);
String outputImageFile = "identificate.png";
String xmlPath = identificate.class.getClassLoader().getResource("cascade_storage.xml").getPath().substring(1);
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
CascadeClassifier faceDetector = new CascadeClassifier(xmlPath);
Mat image = Highgui.imread(inputImagePath);
MatOfRect faceDetections = new MatOfRect();
faceDetector.detectMultiScale(image, faceDetections);
// ���������
for (Rect rect : faceDetections.toArray()) {
Core.rectangle(image, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height), new Scalar(0, 0, 255));
}
// д�뵽�ļ�
Highgui.imwrite(outputImageFile, image);
System.out.print("\nOK!");
}
示例4: preProcessFrame
import org.opencv.highgui.Highgui; //导入方法依赖的package包/类
public Mat preProcessFrame(final Mat mat) {
if (mat.channels() == 1) return mat.clone();
final Mat newMat = new Mat(mat.rows(), mat.cols(), CvType.CV_8UC1);
Imgproc.cvtColor(mat, newMat, Imgproc.COLOR_BGR2GRAY);
if (logger.isTraceEnabled()) {
String filename = String.format("grayscale.png");
final File file = new File(filename);
filename = file.toString();
Highgui.imwrite(filename, newMat);
}
return newMat;
}
示例5: blankRotatedRect
import org.opencv.highgui.Highgui; //导入方法依赖的package包/类
private void blankRotatedRect(Mat mat, final RotatedRect rect) {
final Mat tempMat = Mat.zeros(mat.size(), CvType.CV_8UC1);
final Point points[] = new Point[4];
rect.points(points);
for (int i = 0; i < 4; ++i) {
Core.line(tempMat, points[i], points[(i + 1) % 4], new Scalar(255, 255, 255));
}
final Mat tempMask = Mat.zeros((mat.rows() + 2), (mat.cols() + 2), CvType.CV_8UC1);
Imgproc.floodFill(tempMat, tempMask, rect.center, new Scalar(255, 255, 255), null, new Scalar(0, 0, 0),
new Scalar(254, 254, 254), 4);
if (logger.isTraceEnabled()) {
String filename = String.format("poly.png");
final File file = new File(filename);
filename = file.toString();
Highgui.imwrite(filename, tempMat);
}
mat.setTo(new Scalar(0, 0, 0), tempMat);
}
示例6: LoadImage
import org.opencv.highgui.Highgui; //导入方法依赖的package包/类
public LoadImage(String imgStr,Mat m) {
Highgui.imwrite(imgStr,m);
JFrame frame = new JFrame("My GUI");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setResizable(true);
frame.setLocationRelativeTo(null);
// Inserts the image icon
ImageIcon image = new ImageIcon(imgStr);
frame.setSize(image.getIconWidth()+10,image.getIconHeight()+35);
// Draw the Image data into the BufferedImage
JLabel label1 = new JLabel(" ", image, JLabel.CENTER);
frame.getContentPane().add(label1);
frame.validate();
frame.setVisible(true);}
示例7: main
import org.opencv.highgui.Highgui; //导入方法依赖的package包/类
public static void main(String[] args) {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
String imagePath = "C:\\Users\\admin\\Desktop\\a.png";
FaceDetector faceDetector = new FaceDetector();
Mat[] mats = faceDetector.snipFace(imagePath, new Size(90, 90));
int i=0;
for(Mat mat: mats){
Highgui.imwrite(imagePath.substring(0, imagePath.length()-4)+"Snipped"+i+imagePath.substring(imagePath.length()-4),
mat);
i++;
}
System.out.println("Done!!!");
}
示例8: saveImage
import org.opencv.highgui.Highgui; //导入方法依赖的package包/类
private void saveImage(Mat mat) {
File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "MyAppDir");
if (!mediaStorageDir.exists()) {
if (!mediaStorageDir.mkdirs()) {
Log.e("bifrostcore", "failed to create directory");
return;
}
}
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
File mediaFile;
mediaFile = new File(mediaStorageDir.getPath() + File.separator + "bifrostcore_" + timeStamp + ".png");
Log.w("bifrostcore", "save image to " + mediaFile.toString());
Highgui.imwrite(mediaFile.toString(), mat);
}
示例9: getFrames
import org.opencv.highgui.Highgui; //导入方法依赖的package包/类
private static File[] getFrames(VideoCapture video, int frameFrequency) {
int frameNumber = 1;
Mat frame = new Mat();
File videoFramesDir = Files.createTempDir();
while(video.read(frame)){
if(frameNumber % frameFrequency == 0) {
String res = videoFramesDir.getAbsolutePath() + "/" +
String.format("%08d", frameNumber / frameFrequency) + ".jpg";
Highgui.imwrite(res, frame);
}
frameNumber ++;
}
File [] frames = videoFramesDir.listFiles();
Arrays.sort(frames);
return frames;
}
示例10: saveTo
import org.opencv.highgui.Highgui; //导入方法依赖的package包/类
public void saveTo(String path) {
if (mBitmap != null) {
try {
mBitmap.compress(Bitmap.CompressFormat.PNG, 100, new FileOutputStream(path));
} catch (FileNotFoundException e) {
throw new UncheckedIOException(e);
}
} else {
Highgui.imwrite(path, mMat);
}
}
示例11: surroundFaces
import org.opencv.highgui.Highgui; //导入方法依赖的package包/类
/**
* Creates a new output image from the input image with faces surrounded with green boxes.
* @param image the input image previously analyzed.
* @param faces array of coordinates corresponding to the previously detected faces.
* @param outputFilename the output file name.
* @return true in cas of success when creating the output file. False in case of failure.
*/
public static boolean surroundFaces(Mat image, Rect[] faces, String outputFilename) {
if(outputFilename == null || outputFilename.isEmpty())
throw new RaspoidException("The output filename can't be empty.");
for(Rect face : faces)
Core.rectangle(image,
new Point(face.x, face.y),
new Point(face.x + face.width, face.y + face.height),
new Scalar(0, 255, 0));
return Highgui.imwrite(outputFilename, image);
}
示例12: addShot
import org.opencv.highgui.Highgui; //导入方法依赖的package包/类
private void addShot(Frame workingFrame, PixelCluster pc) {
final Optional<ShotColor> color = pc.getColor(workingFrame.getOriginalMat(), colorDistanceFromRed);
if (!color.isPresent()) {
if (logger.isDebugEnabled()) logger.debug("Processing Shot: Shot Rejected By Lack Of Color Density");
return;
}
final double x = pc.centerPixelX;
final double y = pc.centerPixelY;
if (super.addShot(color.get(), x, y, workingFrame.getTimestamp(), true)
&& Configuration.getConfig().isDebugShotsRecordToFiles()) {
final Mat debugFrame = new Mat();
Imgproc.cvtColor(workingFrame.getOriginalMat(), debugFrame, Imgproc.COLOR_HSV2BGR);
String filename = String.format("shot-%d-%d-%d_orig.png",
cameraManager.cameraTimeToShotTime(workingFrame.getTimestamp()), (int) pc.centerPixelX,
(int) pc.centerPixelY);
final File file = new File(filename);
filename = file.toString();
Highgui.imwrite(filename, debugFrame);
for (final Pixel p : pc) {
if (javafx.scene.paint.Color.GREEN.equals(color.get())) {
final double[] greenColor = { 0, 255, 0 };
debugFrame.put(p.y, p.x, greenColor);
} else {
final double[] redColor = { 0, 0, 255 };
debugFrame.put(p.y, p.x, redColor);
}
}
final File outputfile = new File(
String.format("shot-%d-%d-%d.png", cameraManager.cameraTimeToShotTime(workingFrame.getTimestamp()),
(int) pc.centerPixelX, (int) pc.centerPixelY));
filename = outputfile.toString();
Highgui.imwrite(filename, debugFrame);
}
}
示例13: findPatterns
import org.opencv.highgui.Highgui; //导入方法依赖的package包/类
private List<MatOfPoint2f> findPatterns(Mat mat, boolean findMultiple) {
final List<MatOfPoint2f> patternList = new ArrayList<>();
int count = 0;
while (true) {
final Optional<MatOfPoint2f> boardCorners = findChessboard(mat);
if (boardCorners.isPresent()) {
patternList.add(boardCorners.get());
if (!findMultiple) break;
final RotatedRect rect = getPatternDimensions(boardCorners.get());
blankRotatedRect(mat, rect);
if (logger.isTraceEnabled()) {
String filename = String.format("blanked-box-%d.png", count);
final File file = new File(filename);
filename = file.toString();
Highgui.imwrite(filename, mat);
}
// Shortcut to not try to find three+ patterns
// We never should see more than two but maybe that'll change
// in the future
findMultiple = false;
} else {
break;
}
count++;
}
return patternList;
}
示例14: main
import org.opencv.highgui.Highgui; //导入方法依赖的package包/类
public static void main(String[] args) {
System.out.println(System.getProperty("java.class.path"));
System.out.println(System.getProperty("java.library.path"));
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
VideoCapture camera = new VideoCapture("data/bike.avi");
MatOfByte frame = new MatOfByte();
int i = 0;
while(true){
if (camera.read(frame)){
System.out.println("Frame Obtained");
System.out.println("Captured Frame Width " +
frame.width() + " Height " + frame.height());
System.out.println(frame.dump());
Highgui.imwrite("tmp\\image\\camera"+(i++)+".jpg", frame);
//Highgui.imencode(ext, img, buf)
}else{
break;
}
}
camera.release();
}
示例15: run
import org.opencv.highgui.Highgui; //导入方法依赖的package包/类
public void run() {
System.out.println("\nRunning CopyImage");
// Create a face detector from the cascade file in the resources
// directory.
//CascadeClassifier faceDetector = new CascadeClassifier(getClass().getResource("/lbpcascade_frontalface.xml").getPath());
// For now, just read the image that is in the directory with our java project file
Mat image = Highgui.imread("C:lena.jpg", Highgui.CV_LOAD_IMAGE_COLOR);
//Mat image = Highgui.imread("yellow-tote-top.jpg", Highgui.CV_LOAD_IMAGE_COLOR);
int srcRows = image.rows();
int srcCols = image.cols();
long imgData = image.dataAddr();
System.out.println("Source rows = " + srcRows + " Src columns = " + srcCols);
new LoadImage("C:dst1.jpg",image);
int loadedRows = image.rows();
int loadedCols = image.cols();
System.out.println("Loaded rows = " + loadedRows + " Loaded columns = " + loadedCols);
// Detect faces in the image.
// MatOfRect is a special container class for Rect.
// MatOfRect faceDetections = new MatOfRect();
//faceDetector.detectMultiScale(image, faceDetections);
//System.out.println(String.format("Detected %s faces", faceDetections.toArray().length));
// Draw a bounding box around each face.
//for (Rect rect : faceDetections.toArray()) {
// Core.rectangle(image, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height), new Scalar(0, 255, 0));
//}
// Save the visualized detection.
//String filename = "faceDetection.png";
// For now, just save a copy of the original image.
// Note: that this is also done in the LoadImage function.
String filename = "imageCopy.jpg";
System.out.println(String.format("Writing %s", filename));
Highgui.imwrite(filename, image);
}