Code Monkey home page Code Monkey logo

cnlite_cs's People

Contributors

cronz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

cnlite_cs's Issues

短边自适应

image
private Tensor GetInputs(string imageFilePath, Mat rgbMat, out int new_h, out int new_w)
{

        // Read image
        Mat imageMat = CvInvoke.Imread(imageFilePath, ImreadModes.Color);
        CvInvoke.CvtColor(imageMat, rgbMat, ColorConversion.Bgr2Rgb);
        imageMat.Dispose();

        //取图片最小的边做为短边
        int short_size = rgbMat.Height < rgbMat.Width ? rgbMat.Height : rgbMat.Width;
        //测试发现如果短边小于96,会造成识别不出来或者识别不完全,要保证短边不小于96
        if (short_size < 96)
        {
            short_size = 96;
        }
        //短边 取整为32的倍数
        short_size = 32 * (short_size / 32);

        double scale_h = 0, tar_w = 0, scale_w = 0, tar_h = 0;

        if (rgbMat.Height < rgbMat.Width)
        {
            scale_h = short_size * 1.0 / rgbMat.Height;
            tar_w = rgbMat.Width * scale_h * 1.0;
            tar_w = tar_w - tar_w % 32;
            tar_w = Math.Max(32, tar_w);
            scale_w = tar_w / rgbMat.Width;
        }
        else
        {
            scale_w = short_size * 1.0 / rgbMat.Width;
            tar_h = rgbMat.Height * scale_w * 1.0;
            tar_h = tar_h - tar_h % 32;
            tar_h = Math.Max(32, tar_h);
            scale_h = tar_h / rgbMat.Height;
        }

        new_h = (int)(scale_h * rgbMat.Height);
        new_w = (int)(scale_w * rgbMat.Width);

        Mat imgResized = new Mat(new_h, new_w, DepthType.Cv32F, 3);
        CvInvoke.Resize(rgbMat, imgResized, new Size(new_w, new_h));

        return GetTensorInputFromImg(imgResized);
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.