本文整理汇总了Java中org.opencv.highgui.Highgui类的典型用法代码示例。如果您正苦于以下问题:Java Highgui类的具体用法?Java Highgui怎么用?Java Highgui使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Highgui类属于org.opencv.highgui包,在下文中一共展示了Highgui类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: imshow
import org.opencv.highgui.Highgui; //导入依赖的package包/类
/**
* Display image in a frame
*
* @param title
* @param img
*/
public static void imshow(String title, Mat img) {
// Convert image Mat to a jpeg
MatOfByte imageBytes = new MatOfByte();
Highgui.imencode(".jpg", img, imageBytes);
try {
// Put the jpeg bytes into a JFrame window and show.
JFrame frame = new JFrame(title);
frame.getContentPane().add(new JLabel(new ImageIcon(ImageIO.read(new ByteArrayInputStream(imageBytes.toArray())))));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
frame.setLocation(30 + (windowNo*20), 30 + (windowNo*20));
windowNo++;
} catch (Exception e) {
e.printStackTrace();
}
}
示例2: 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.");
}
}
示例3: FileUtil
import org.opencv.highgui.Highgui; //导入依赖的package包/类
public FileUtil(String sourceFileName, int length, int width) throws IOException{
this.length = length;
this.width = width;
this.sourceFileName = sourceFileName;
outputArray = new int[this.length][this.width];
sourceMat = Highgui.imread(this.sourceFileName);
for(String tempalteFileName : templateFileNames){
InputStream input = this.getClass().getResourceAsStream("/" + tempalteFileName);
FileOutputStream fos = new FileOutputStream(tempFileName);
byte[] b = new byte[1024];
while((input.read(b)) != -1){
fos.write(b);
}
input.close();
fos.close();
templateMat.add(Highgui.imread(tempFileName));
}
File file = new File(tempFileName);
file.delete();
Process();
}
示例4: 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);
}
示例5: loadResource
import org.opencv.highgui.Highgui; //导入依赖的package包/类
public static Mat loadResource(Context context, int resourceId, int flags) throws IOException
{
InputStream is = context.getResources().openRawResource(resourceId);
ByteArrayOutputStream os = new ByteArrayOutputStream(is.available());
byte[] buffer = new byte[4096];
int bytesRead;
while ((bytesRead = is.read(buffer)) != -1) {
os.write(buffer, 0, bytesRead);
}
is.close();
Mat encoded = new Mat(1, os.size(), CvType.CV_8U);
encoded.put(0, 0, os.toByteArray());
os.close();
Mat decoded = Highgui.imdecode(encoded, flags);
encoded.release();
return decoded;
}
示例6: main
import org.opencv.highgui.Highgui; //导入依赖的package包/类
/**
* Command-line interface.
* @param args unused here.
*/
public static void main(String[] args) {
// Load the OpenCV native library.
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
// Take a picture with the camera pi
String pictureId = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss").format(new Date());
PictureConfig pictureConfig = new PictureConfig("capture_" + pictureId, 640, 480);
pictureConfig.setVerticalFlip(true);
String filePath = CameraPi.takePicture(pictureConfig).getFilePath();
// Look for faces
Mat image = Highgui.imread(filePath);
Rect[] faces = FaceDetector.detectFaces(image);
Tools.log(String.format("%s faces detected", faces.length));
Tools.log("Input file path: " + filePath);
// Create a new picture, with detected faces
FaceDetector.surroundFaces(image, faces, "output_" + pictureId + ".jpg");
Tools.log("Output file: " + "output_" + pictureId + ".jpg");
}
示例7: setupCamera
import org.opencv.highgui.Highgui; //导入依赖的package包/类
public void setupCamera(int width, int height) {
Log.i(TAG, "setupCamera("+width+", "+height+")");
synchronized (this) {
if (mCamera != null && mCamera.isOpened()) {
List<Size> sizes = mCamera.getSupportedPreviewSizes();
int mFrameWidth = width;
int mFrameHeight = height;
// selecting optimal camera preview size
{
double minDiff = Double.MAX_VALUE;
for (Size size : sizes) {
if (Math.abs(size.height - height) < minDiff) {
mFrameWidth = (int) size.width;
mFrameHeight = (int) size.height;
minDiff = Math.abs(size.height - height);
}
}
}
mCamera.set(Highgui.CV_CAP_PROP_FRAME_WIDTH, mFrameWidth);
mCamera.set(Highgui.CV_CAP_PROP_FRAME_HEIGHT, mFrameHeight);
}
}
}
示例8: onActivityResult
import org.opencv.highgui.Highgui; //导入依赖的package包/类
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == TAKE_PHOTO) {
if (resultCode == RESULT_OK) {
// new photo taken
// read the photo
im = Highgui.imread(dir.getAbsolutePath()+"/calibrate"+PHOTOS+".jpg");
// find corners in an asynctask because it is a heavy operation
new FindCornersTask(this).execute(im);
// boolean ret = Calib3d.findChessboardCorners(im, new Size(9,6), corners);
// Calib3d.drawChessboardCorners(im, new Size(9,6), corners, ret);
// save it
// Highgui.imwrite(dir.getAbsolutePath()+"/calibrate"+PHOTOS+"-drawn.jpg", im);
// insert it into the layout
// ImageView photo = (ImageView) findViewById(R.id.photo);
// Bitmap bmp = Bitmap.createBitmap(im.cols(), im.rows(), Bitmap.Config.ARGB_8888);
// org.opencv.android.Utils.matToBitmap(im,bmp);
// photo.setImageBitmap(bmp);
PHOTOS++;
}
}
}
示例9: mat2Image
import org.opencv.highgui.Highgui; //导入依赖的package包/类
/**
* Convert a {@link Mat} object (OpenCV) in the corresponding {@link 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 bitmap format
if(Highgui.imencode(".bmp", frame, buffer)){
System.out.println("Highgui is successful");
}
else{
System.out.println("Highgui is unsuccessful");
}
// build and return an Image created from the image encoded in the
// buffer
return new Image(new ByteArrayInputStream(buffer.toArray()));
}
示例10: 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!");
}
示例11: 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;
}
示例12: 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);
}
示例13: bufferedImageToMat
import org.opencv.highgui.Highgui; //导入依赖的package包/类
protected static Mat bufferedImageToMat(BufferedImage buf) throws IOException {
// Get bytes
byte[] bytes = bufferedImageToBytes(buf);
// Map to Bytes
Byte[] bigByteArray = new Byte[bytes.length];
for (int i=0; i < bytes.length; i++)
bigByteArray[i] = new Byte(bytes[i]);
// Convert bytes to matrix
List<Byte> matlist = Arrays.asList(bigByteArray);
Mat img = new Mat();
img = Converters.vector_char_to_Mat(matlist);
img = Highgui.imdecode(img, Highgui.CV_LOAD_IMAGE_COLOR);
return img;
}
示例14: readImageFromPath
import org.opencv.highgui.Highgui; //导入依赖的package包/类
public static Mat readImageFromPath(String filePath) throws IOException {
if (ReplicaUtils.isHDFS(filePath)) {
return ReplicaUtils.readFromHDFS(filePath);
}
else if (ReplicaUtils.isURL(filePath)) {
return ReplicaUtils.getImageContentFromURL(new URL(filePath));
}
else {
if (ReplicaUtils.fileExists(filePath)) {
return Highgui.imread(filePath, Highgui.CV_LOAD_IMAGE_ANYCOLOR);
}
else {
throw new IOException("Path '" + filePath + "' does not exist");
}
}
}
示例15: byteswritableToMat
import org.opencv.highgui.Highgui; //导入依赖的package包/类
public static Mat byteswritableToMat(BytesWritable inputBW) {
// Compute input bytes
byte[] imageFileBytes = inputBW.getBytes();
Byte[] bigByteArray = new Byte[imageFileBytes.length];
for (int i=0; i<imageFileBytes.length; i++) {
bigByteArray[i] = new Byte(imageFileBytes[i]);
}
// To list
List<Byte> matlist = Arrays.asList(bigByteArray);
// Convert into image matrix
Mat img = new Mat();
img = Converters.vector_char_to_Mat(matlist);
img = Highgui.imdecode(img, Highgui.CV_LOAD_IMAGE_COLOR);
return img;
}