zoukankan      html  css  js  c++  java
  • 基于opencv图片切割

      基于opencv图片切割为n个3*3区块

      工作原因,切割图片,任务急,暂留调通的源码,留以后用.

    package com.rosetta.image.test;
    
    import org.opencv.core.Core;
    import org.opencv.core.Mat;
    import org.opencv.core.Rect;
    import org.opencv.highgui.Highgui;
    
    /**
     * @Author: nya
     * @Date: 18-8-28 下午5:50
     */
    public class SplitImage {
    
        public static void main(String[] args ){
            System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
            Mat image = Highgui.imread("/home/han/images/55.png");
            //System.out.println( "mat = " + image.dump() );
    
            int m = 5;
            int n = 5;
    
            int height = image.rows();
            int width  = image.cols();
            System.out.println("height:"+height+" "+width);
            int ceil_height = height/m;
            int ceil_width  = width/n;
            System.out.println("ceil_height:"+ceil_height+" ceil_"+ceil_width);
    
            String filename = "/home/han/images/split/sub";
    
            int x = m / 3;
            int y = m % 3;
            int z = (x - 1) * 3 + y + 1;
            for(int i = 0; i<z; i++ ) {
                for(int j = 0; j<z; j++){
                    int a = i * ceil_width ;
                    int b = j * ceil_height;
                    System.out.println(a+","+b+","+ceil_width+","+ceil_height);
                    Rect rect = new Rect(a,b,3*ceil_width,3*ceil_height);
                    Mat roi_img = new Mat(image,rect);
                    //Mat tmp_img = new Mat();
    
                    //roi_img.copyTo(tmp_img);
    
                    Highgui.imwrite(filename+"_"+i+"_"+j+".jpg", roi_img);
                }
            }
        }
    
    }

      图片素材

  • 相关阅读:
    LVM 逻辑卷管理
    运维自动化工具 Kickstart
    运维自动化工具 Cobbler
    Python 环境
    Zabbix Agent 自动、主动注册
    Zabbix Proxy 分布式监控
    PHP 性能优化之 PHP-FPM
    PHP 缓存插件之 Zend Opcache ( 取代 APC )
    Alternative PHP Cache ( APC )
    Tomcat ( 单机多 Tomcat 并存 )
  • 原文地址:https://www.cnblogs.com/nyatom/p/9552901.html
Copyright © 2011-2022 走看看