當前位置: 首頁>>代碼示例>>Java>>正文


Java Highgui類代碼示例

本文整理匯總了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();
    }
}
 
開發者ID:fossasia,項目名稱:zooracle,代碼行數:27,代碼來源:OpenCVUtils.java

示例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.");
}
}
 
開發者ID:JuanJoseFJ,項目名稱:ProyectoPacientes,代碼行數:19,代碼來源:JDIngresarPaciente.java

示例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();
}
 
開發者ID:littleliang,項目名稱:PopStar,代碼行數:22,代碼來源:FileUtil.java

示例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);
}
 
開發者ID:Raspoid,項目名稱:raspoid,代碼行數:25,代碼來源:TestOpenCVInstallation.java

示例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;
}
 
開發者ID:hollaus,項目名稱:TinyPlanetMaker,代碼行數:22,代碼來源:Utils.java

示例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");
}
 
開發者ID:Raspoid,項目名稱:raspoid,代碼行數:25,代碼來源:FaceDetectorExample.java

示例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);
        }
    }

}
 
開發者ID:davrempe,項目名稱:cardboardAR-lib,代碼行數:27,代碼來源:ViewBase.java

示例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++;
			}
		}
	}
 
開發者ID:davrempe,項目名稱:cardboardAR-lib,代碼行數:25,代碼來源:CameraCalibrationActivity.java

示例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()));
}
 
開發者ID:npw3202,項目名稱:ASL-recognition,代碼行數:24,代碼來源:ObjectRecognitionController.java

示例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!");
}
 
開發者ID:nthf,項目名稱:yourface,代碼行數:24,代碼來源:identificate.java

示例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;
}
 
開發者ID:phrack,項目名稱:ShootOFF,代碼行數:17,代碼來源:AutoCalibrationManager.java

示例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);
}
 
開發者ID:phrack,項目名稱:ShootOFF,代碼行數:23,代碼來源:AutoCalibrationManager.java

示例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;
}
 
開發者ID:DaniUPC,項目名稱:near-image-replica-detection,代碼行數:18,代碼來源:ReplicaUtils.java

示例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");
		}
	}
}
 
開發者ID:DaniUPC,項目名稱:near-image-replica-detection,代碼行數:17,代碼來源:Image.java

示例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;
  }
 
開發者ID:DaniUPC,項目名稱:near-image-replica-detection,代碼行數:17,代碼來源:SeqFileComputeFeatures.java


注:本文中的org.opencv.highgui.Highgui類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。