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


Java Highgui.imencode方法代碼示例

本文整理匯總了Java中org.opencv.highgui.Highgui.imencode方法的典型用法代碼示例。如果您正苦於以下問題:Java Highgui.imencode方法的具體用法?Java Highgui.imencode怎麽用?Java Highgui.imencode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.opencv.highgui.Highgui的用法示例。


在下文中一共展示了Highgui.imencode方法的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: 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

示例3: toBufferedImage

import org.opencv.highgui.Highgui; //導入方法依賴的package包/類
public static BufferedImage toBufferedImage(Mat source) throws IOException
{
   MatOfByte bytemat = new MatOfByte();

   try 
   {
      Highgui.imencode(".jpg", source, bytemat);
      byte[] bytes = bytemat.toArray();

      try (InputStream in = new ByteArrayInputStream(bytes))
      {
         BufferedImage img = ImageIO.read(in);
         return img;
      }
      catch (Exception e) 
      {
         throw new IOException("Failed to convert OpenCV matrix to buffered image");
      }
   }
   finally
   {
      if (bytemat != null)
         bytemat.release();
   }
}
 
開發者ID:tcat-tamu,項目名稱:Document-Image-Analysis,代碼行數:26,代碼來源:SimpleImageSegmenter.java

示例4: run

import org.opencv.highgui.Highgui; //導入方法依賴的package包/類
@Override
public void run() {
    synchronized (this) {
        while (runnable) {
            if (webSource.grab()) {
                try {
                    webSource.retrieve(fm);
                    Graphics g = cameraPane.getGraphics();
                    faceDetector.detectMultiScale(fm, faceDetections);

                    for (Rect rect : faceDetections.toArray()) {
                        Imgproc.rectangle(fm, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height), new Scalar(0, 255, 0));
                        // rectCrop = new Rect(rect.x, rect.y, rect.width, rect.height);// crop only face

                    }
                    Highgui.imencode(".bmp", fm, mem);
                    Image im = ImageIO.read(new ByteArrayInputStream(mem.toArray()));
                    BufferedImage buff = (BufferedImage) im;
                    if (g.drawImage(buff, 0, 0, getWidth(), getHeight() - 150, 0, 0, buff.getWidth(), buff.getHeight(), null)) {
                        if (runnable == false) {
                            System.out.println("Paused ..... ");
                            this.wait();
                        }
                    }
                } catch (Exception ex) {
                    ex.toString();
                }

            }
        }
    }
}
 
開發者ID:javaspecial,項目名稱:Face-detection-and-recognition-desktop-application,代碼行數:33,代碼來源:FaceRecognizeFrame.java

示例5: run

import org.opencv.highgui.Highgui; //導入方法依賴的package包/類
@Override
public void run() {
    synchronized (this) {
        while (runnable) {
            if (webSource.grab()) {
                try {
                    webSource.retrieve(fm);
                    Graphics g = cameraPane.getGraphics();
                    faceDetector.detectMultiScale(fm, faceDetections);
                    for (Rect rect : faceDetections.toArray()) {
                        Imgproc.rectangle(fm, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height), new Scalar(0, 255, 0));
                    }

                    Highgui.imencode(".bmp", fm, mem);
                    Image im = ImageIO.read(new ByteArrayInputStream(mem.toArray()));
                    BufferedImage buff = (BufferedImage) im;
                    if (g.drawImage(buff, 0, 0, getWidth(), getHeight(), 0, 0, buff.getWidth(), buff.getHeight(), null)) {

                        if (runnable == false) {
                            System.out.println("Paused ..... ");
                            this.wait();
                        }
                    }
                } catch (Exception ex) {
                    ex.toString();
                }
            }
        }
    }
}
 
開發者ID:javaspecial,項目名稱:Face-detection-and-recognition-desktop-application,代碼行數:31,代碼來源:FaceDetectorSecurityCamera.java

示例6: run

import org.opencv.highgui.Highgui; //導入方法依賴的package包/類
@Override
public void run() {
    synchronized (this) {
        while (runnable) {
            if (webSource.grab()) {
                try {
                    webSource.retrieve(fm);

                    Graphics g = cameraPane.getGraphics();
                    faceDetector.detectMultiScale(fm, faceDetections);

                    for (Rect rect : faceDetections.toArray()) {
                        Imgproc.rectangle(fm, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height), new Scalar(0, 255, 0));
                          rectCrop = new Rect(rect.x, rect.y, rect.width, rect.height);// crop only face

                    }
                    Highgui.imencode(".bmp", fm, mem);
                    Image im = ImageIO.read(new ByteArrayInputStream(mem.toArray()));
                    BufferedImage buff = (BufferedImage) im;
                    if (g.drawImage(buff, 0, 0, getWidth(), getHeight() - 150, 0, 0, buff.getWidth(), buff.getHeight(), null)) {
                        if (runnable == false) {
                            System.out.println("Paused ..... ");
                            this.wait();
                        }
                    }
                } catch (Exception ex) {
                    ex.toString();
                }

            }
        }
    }
}
 
開發者ID:javaspecial,項目名稱:Face-detection-and-recognition-desktop-application,代碼行數:34,代碼來源:FaceDetectCropTest.java

示例7: run

import org.opencv.highgui.Highgui; //導入方法依賴的package包/類
@Override
public void run() {
    synchronized (this) {
        while (runnable) {
            if (webSource.grab()) {
                try {
                    webSource.retrieve(fm);
                    Graphics g = jPanel1.getGraphics();
                    faceDetector.detectMultiScale(fm, faceDetections);
                    for (Rect rect : faceDetections.toArray()) {
                        Imgproc.rectangle(fm, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height), new Scalar(0, 255, 0));
                    }
                    Highgui.imencode(".bmp", fm, mem);
                    Image im = ImageIO.read(new ByteArrayInputStream(mem.toArray()));
                    BufferedImage buff = (BufferedImage) im;
                    if (g.drawImage(buff, 0, 0, getWidth(), getHeight(), 0, 0, buff.getWidth(), buff.getHeight(), null)) {
                        if (runnable == false) {
                            System.out.println("Paused ..... ");
                            this.wait();
                        }
                    }
                } catch (Exception ex) {
                    System.out.println("Error");
                }
            }
        }
    }
}
 
開發者ID:javaspecial,項目名稱:Face-detection-and-recognition-desktop-application,代碼行數:29,代碼來源:Camera.java

示例8: run

import org.opencv.highgui.Highgui; //導入方法依賴的package包/類
@Override
public  void run()
{
    synchronized(this)
    {
        while(runnable)
        {
            if(webSource.grab())
            {
  	try
                    {
                        webSource.retrieve(frame);
   Highgui.imencode(".bmp", frame, mem);
   Image im = ImageIO.read(new ByteArrayInputStream(mem.toArray()));

   BufferedImage buff = (BufferedImage) im;
   Graphics g=CamWeb.getGraphics();

   if (g.drawImage(buff, 0, 0, getWidth(), getHeight() -150 , 0, 0, buff.getWidth(), buff.getHeight(), null))
   
   if(runnable == false)
                        {
   	System.out.println("Going to wait()");
   	this.wait();
   }
}
catch(Exception ex)
                     {
   System.out.println();
                     }
            }
        }
    }
 }
 
開發者ID:JuanJoseFJ,項目名稱:ProyectoPacientes,代碼行數:35,代碼來源:JDIngresarPaciente.java

示例9: writeOcrResult

import org.opencv.highgui.Highgui; //導入方法依賴的package包/類
private static void writeOcrResult(DigitalType digitalType, DigitalTypeClass digitalTypeClass) throws IOException {
  File ocrFile = buildOcrFileName(digitalType, digitalTypeClass);
  Mat mat = OpenCvImage.getMatFromSimDocBinaryDat(digitalType.getBytes());
  MatOfByte matOfByte = new MatOfByte();
  Highgui.imencode(".png", mat, matOfByte, new MatOfInt(Highgui.CV_IMWRITE_PNG_COMPRESSION, 0));
  FileUtils.writeByteArrayToFile(ocrFile, matOfByte.toArray());
}
 
開發者ID:Orange-OpenSource,項目名稱:documentare-simdoc,代碼行數:8,代碼來源:OcrApp.java

示例10: exportDigitalType

import org.opencv.highgui.Highgui; //導入方法依賴的package包/類
private static void exportDigitalType(DigitalType digitalType) throws IOException {
  Mat mat = OpenCvImage.rawToMat(digitalType.getBytes());
  MatOfByte matOfByte = new MatOfByte();
  Highgui.imencode(".png", mat, matOfByte, new MatOfInt(Highgui.CV_IMWRITE_PNG_COMPRESSION, 0));
  String outImageName = String.format("%s/%d_%d.png", DEBUG_OUT_DIR, digitalType.y(), digitalType.x());
  String outRawImageName = String.format("%s/%d_%d.raw", DEBUG_OUT_DIR, digitalType.y(), digitalType.x());
  FileUtils.writeByteArrayToFile(new File(outImageName), matOfByte.toArray());
  FileUtils.writeByteArrayToFile(new File(outRawImageName), digitalType.getBytes());
}
 
開發者ID:Orange-OpenSource,項目名稱:documentare-simdoc,代碼行數:10,代碼來源:LineDetectionApp.java

示例11: writeImage

import org.opencv.highgui.Highgui; //導入方法依賴的package包/類
private void writeImage(DigitalType digitalType) throws IOException {
  Mat mat = OpenCvImage.rawToMat(digitalType.getBytes());
  MatOfByte matOfByte = new MatOfByte();
  Highgui.imencode(".png", mat, matOfByte, new MatOfInt(Highgui.CV_IMWRITE_PNG_COMPRESSION, 0));
  String outImageName = String.format("%s/%d_%d.png", imagesDir, digitalType.y(), digitalType.x());
  FileUtils.writeByteArrayToFile(new File(outImageName), matOfByte.toArray());
}
 
開發者ID:Orange-OpenSource,項目名稱:documentare-simdoc,代碼行數:8,代碼來源:GraphWriterPdf.java

示例12: run

import org.opencv.highgui.Highgui; //導入方法依賴的package包/類
public void run() {
    synchronized (this) {
        while (runnable) {
            if (webSource.grab()) {
                try {
                    webSource.retrieve(frame);
                    Graphics g = panel.getGraphics();
                    faceDetector.detectMultiScale(frame, faceDetections);
                    for (Rect rect : faceDetections.toArray()) {
                        Core.rectangle(frame, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height),
                                new Scalar(0, 255,0));
                        int xVal = rect.x;
                        if(xVal > 250){
                        	System.out.println("left");
        					PongCourt.ball.left();
        		            PongCourt.ball.setVelocity(-6, PongCourt.ball.velocityY);
                        }
                        if(xVal < 250){
                        	System.out.println("right");
        					PongCourt.ball.setVelocity(6, PongCourt.ball.velocityY);
        		            PongCourt.ball.right();
                        }
                    }
                    Highgui.imencode(".bmp", frame, mem);
                    Image im = ImageIO.read(new ByteArrayInputStream(mem.toArray()));
                    BufferedImage buff = (BufferedImage) im;
                    if (g.drawImage(buff, 0, 0, getWidth(), getHeight()-150 , 0, 0, buff.getWidth(), buff.getHeight(), null)) {
                        if (runnable == false) {
                            System.out.println("Paused ..... ");
                            this.wait();
                        }
                    }
                } catch (Exception ex) {
                    System.out.println("Error");
                }
            }
        }
    }
}
 
開發者ID:srikrishnamurthy,項目名稱:MightyMouse,代碼行數:40,代碼來源:FaceDetection.java

示例13: paint

import org.opencv.highgui.Highgui; //導入方法依賴的package包/類
@Override
public void paint(Graphics g) {
    webSource.open(0);
    timer.start();
    webSource.retrieve(frame);
    Mat frame2 = frame.clone();
    Size sz = new Size(200, 200);
    Imgproc.resize(frame2, frame, sz);
    faceDetector.detectMultiScale(frame, faceDetections);
    for (Rect rect : faceDetections.toArray()) {
        Core.rectangle(frame, new org.opencv.core.Point(rect.x, rect.y),
                new org.opencv.core.Point(rect.x + rect.width, rect.y + rect.height),
                new Scalar(0, 255, 0));
    }
    Highgui.imencode(".bmp", frame, mem);
    Image im = null;
    try {
        im = ImageIO.read(new ByteArrayInputStream(mem.toArray()));
    } catch (IOException e) {
        e.printStackTrace();
    }

    BufferedImage buff = (BufferedImage) im;
    if(g.drawImage(buff, 0, 0, getWidth(), getHeight()-150 , 0, 0, buff.getWidth(),
            buff.getHeight(), null)){
        System.out.println("Success");
    }else{
        System.out.println("problem");
    }
}
 
開發者ID:npw3202,項目名稱:ASL-recognition,代碼行數:31,代碼來源:WebcamPanel2.java

示例14: setCompressedImage

import org.opencv.highgui.Highgui; //導入方法依賴的package包/類
private void setCompressedImage(Mat inputFrame, tms_ss_rcnn.obj_detectionRequest request) throws IOException {
    Time time = mConnectedNode.getCurrentTime();
    request.getImage().getHeader().setStamp(time);
    request.getImage().getHeader().setFrameId("ObjectDetection");
    request.getImage().getHeader().setSeq(sequenceNumber++);
    request.getImage().setFormat("jpg");

    MatOfByte buf = new MatOfByte();
    Highgui.imencode(".jpg", inputFrame, buf);
    ChannelBufferOutputStream stream = new ChannelBufferOutputStream(MessageBuffers.dynamicBuffer());
    stream.write(buf.toArray());

    request.getImage().setData(stream.buffer().copy());
}
 
開發者ID:kazuto1011,項目名稱:ros-tms-perception,代碼行數:15,代碼來源:ObjectDetectionClient.java

示例15: matToBufferedImage

import org.opencv.highgui.Highgui; //導入方法依賴的package包/類
/**
 * Convert an OpenCV Mat to an AWT BufferedImage
 * @param mat the OpenCV matrix
 * @return the equivalent BufferedImage
 */
private BufferedImage matToBufferedImage(Mat mat) {
    MatOfByte bytemat = new MatOfByte();
    Highgui.imencode(".jpg", mat, bytemat);
    byte[] bytes = bytemat.toArray();
    BufferedImage im = null;
    try {
        im = ImageIO.read(new ByteArrayInputStream(bytes));
    } catch (IOException ex) {
        Logger.getLogger(AcquireSampleImages.class.getName()).log(Level.SEVERE, null, ex);
    }
    return im;
}
 
開發者ID:LuNaTeCs-316,項目名稱:LuNaCV,代碼行數:18,代碼來源:CVMatPanel.java


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