• 大小: 107KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-24
  • 语言: Java
  • 标签: OpenCV  Java  ROI  

资源简介

OpenCV + Java(Android) 设置ROI,说明参见http://blog.csdn.net/MengchiCMC/article/details/74352122

资源截图

代码片段和文件信息

package com.mengchicmc;

import org.opencv.core.*;
import org.opencv.core.Point;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;

import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferByte;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;

/**
 * Created by MengchiCMC on 2017-6-14.
 */
public class MatView {

    /**
     * Open a image file
     *
     * @param filePath the path of the image to open
     * @return image in the form of Mat
     * @throws Exception There is no image to open in this file path
     */
    public static Mat openFile(String filePath) throws Exception {
        Mat image = new Mat();

        image = Imgcodecs.imread(filePath);
        if (image.dataAddr() == 0) {
            throw new Exception(“Couldn‘t open file“);
        }

        return image;
    }


    /**
     * Display Mat image
     *
     * @param image
     */
    public static void imshow(Mat image) {
        imshow(image image.cols() image.rows() ““);
    }

    public static void imshow(Mat image String windowName) {
        imshow(image image.cols() image.rows() windowName);
    }

    public static void imshow(Mat image int width int height) {
        imshow(image width height ““);
    }

    public static void imshow(Mat image int width int height String windowName) {
        if (image.dataAddr() != 0) {
            setSystemLookAndFeel();

            Jframe jframe = new Jframe(windowName);
            JLabel imageView = new JLabel();
            final JScrollPane imageScrollPane = new JScrollPane(imageView);
            imageScrollPane.setPreferredSize(new Dimension(width height));  // set window size
            jframe.add(imageScrollPane BorderLayout.CENTER);
            jframe.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

            Image loadedImage = Mat2BufferedImage(image);
            imageView.setIcon(new ImageIcon(loadedImage));
            jframe.pack();
            jframe.setLocationRelativeTo(null);
            jframe.setVisible(true);
        } else {
            System.out.println(“Mat is empty!“);
        }
    }

    private static void setSystemLookAndFeel() {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (UnsupportedLookAndFeelException e) {
            e.printStackTrace();
        }
    }

    /**
     * Transform picture type from Mat to BufferedImage
     *
     * @param matrix
     * @return
     */
    public static Image Mat2BufferedImag

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件         97  2017-07-04 18:58  ROISetting\.idea\description.html

     文件        301  2017-07-04 19:01  ROISetting\.idea\libraries\opencv_310.xml

     文件        489  2017-07-04 18:58  ROISetting\.idea\misc.xml

     文件        267  2017-07-04 18:59  ROISetting\.idea\modules.xml

     文件         91  2017-07-04 18:58  ROISetting\.idea\project-template.xml

     文件       8792  2017-07-04 19:08  ROISetting\.idea\uiDesigner.xml

     文件      48815  2017-07-04 21:30  ROISetting\.idea\workspace.xml

     文件       3978  2017-07-04 19:15  ROISetting\out\production\ROISetting\com\mengchicmc\MatView.class

     文件       3401  2017-07-04 21:29  ROISetting\out\production\ROISetting\com\mengchicmc\ROISetting.class

     文件      93568  2017-07-04 19:07  ROISetting\picture\clock.jpg

     文件        606  2017-07-04 19:19  ROISetting\ROISetting.iml

     文件       3653  2017-07-04 19:04  ROISetting\src\com\mengchicmc\MatView.java

     文件       3458  2017-07-04 21:30  ROISetting\src\com\mengchicmc\ROISetting.java

     目录          0  2017-07-04 21:29  ROISetting\out\production\ROISetting\com\mengchicmc

     目录          0  2017-07-04 19:15  ROISetting\out\production\ROISetting\com

     目录          0  2017-07-04 19:15  ROISetting\out\production\ROISetting

     目录          0  2017-07-04 21:30  ROISetting\src\com\mengchicmc

     目录          0  2017-07-04 18:59  ROISetting\.idea\inspectionProfiles

     目录          0  2017-07-04 19:01  ROISetting\.idea\libraries

     目录          0  2017-07-04 19:02  ROISetting\out\production

     目录          0  2017-07-04 18:58  ROISetting\src\com

     目录          0  2017-07-04 21:30  ROISetting\.idea

     目录          0  2017-07-04 18:59  ROISetting\gen

     目录          0  2017-07-04 19:02  ROISetting\out

     目录          0  2017-07-04 19:07  ROISetting\picture

     目录          0  2017-07-04 18:58  ROISetting\src

     目录          0  2017-07-04 19:19  ROISetting

----------- ---------  ---------- -----  ----

               167516                    27



............此处省略0个文件信息

评论

共有 条评论