GithubHelp home page GithubHelp logo

huoshulei / sand Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jomes/sand

0.0 2.0 0.0 1007 KB

Using JNI to achieve Sobel operator image edge detection使用JNI实现Sobel算子图像边缘检测 https://github.com/Jomes/sand

CMake 11.38% C++ 46.51% C 26.50% Java 15.60%

sand's Introduction

sand

Sand is Android library that it is using JNI to achieve Sobel operator image edge detection. it's easy to build a picture like sand .

Screenshot

sand

Build

Step 1. Add the JitPack repository to your build file

add the JitPack maven to your project in root build.gradle

allprojects {
    repositories {
        maven { url 'https://jitpack.io' }
    }
}

Step 2. Add module dependency build.gradle

 dependencies {
     	  compile 'com.github.Jomes:sand:v0.01'

 } 

That's it!

How to use

you can get Bitmap from SandPic class,you need to provide original Bitmap、threshold、pointNum。

Bitmap bitmap = SandPic.getInstance().tramform(originalBitmap,thre,pointNum);

there is a important tramform method in the SandPic class. it get pixels array from JNI.

public Bitmap tramform(Bitmap bitmap,int threshold,int ponitNum ){
        int width =  bitmap.getWidth();
        int height = bitmap.getHeight();
        Bitmap newImage = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(newImage);
        Paint paint = new Paint();
        paint.setAntiAlias(false);
        paint.setStyle(Paint.Style.STROKE);
        int pixels[] = new int [width*height];
        bitmap.getPixels(pixels,0,width,0,0,width,height);
        int[] generate = generate(pixels, width, height, threshold, ponitNum);
        for (int i = 0, n = generate.length; i + 1 < n; i += 2) {
                int x = generate[i]>0? generate[i]:0;
                int y = generate[i+1] >0?generate[i+1]:0 ;
                int color = bitmap.getPixel(x,y);
                paint.setColor(color);
                canvas.drawCircle(x, y, 1, paint);
            }

        return newImage;
    }

License

Copyright 2017 jomeslu [email protected]

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

sand's People

Contributors

jomes avatar

Watchers

James Cloos avatar 霍述雷 avatar

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.