Android 图片人脸识别剪切

作者: mm_cuckoo | 来源:发表于2017-06-12 14:56 被阅读152次

场景

在开发中我们经常需要对图片以人脸为中心进行剪切并显示,这时就需要下面这个工具了。

实现效果

实现效果

Demo及工程地址:https://github.com/CNCFOX/ImageViewClip

项目参考及引用

使用库: http://code.taobao.org/p/tclip/
参考项目:https://github.com/beartung/tclip-android
本项目参考以上上面及识别库进行修改封装打包,意在更方便灵活使用。

项目使用

下载工具 jar(IVClip_V1.0.jar) : https://github.com/CNCFOX/ImageViewClip/raw/master/Libs/IVClip_V1.0.jar

下载so文件:https://github.com/CNCFOX/ImageViewClip/raw/master/Libs/so_File.zip

将下载的jar.so 文件加入到项目中。

API 说明

在项目中使用如下API即可:

CImageView

这是一个继承ImageView的图片控件,可以直接在xml 中进行使用:

<com.cfox.ivcliplib.CImageView
    android:src="@mipmap/img"
    android:layout_width="80dp"
    android:layout_height="80dp" />

CImageUtils

说明:这里的宽和高不是显示的宽和高,指的是剪切时的宽和高。实际显示宽和高由自己设定,如果将ImageView 控件的宽和高设置为wrap_content此时的宽和高即为剪切的宽和高。

  • crop(ImageView imageView , int width, int height)
    将指定的ImageView 中的图片剪切指定大小

    imageView : 被处理的ImageView 控件
    width : 宽
    height : 高
    无返回值

    使用示例:

    ImageView mImg = (ImageView) findViewById(R.id.img);
    CImageUtils.instance(this).crop(mImg,400,400);
    
  • cropToBitmap(ImageView imageView, int width, int height)
    将指定的ImageView 中的图片剪切指定大小,返回剪切后图片以Bitmap类型。

    imageView : 被处理的ImageView 控件
    width : 宽
    height : 高
    返回值 : Bitmap

    使用示例:

    ImageView mImgA_A = (ImageView) findViewById(R.id.img_a_a);
    ImageView mBaseView = (ImageView) findViewById(R.id.img_base1);
    
    Bitmap clipBitmap = CImageUtils.instance(this).cropToBitmap(mBaseView,400,400);
    mImgA_A.setImageBitmap(clipBitmap);
    
  • cropToBitmap(Bitmap imageBitmap, int width, int height)
    将指定的Bitmap图片,剪切指定大小,返回剪切后图片以Bitmap类型。

    imageBitmap : Bitmap图片
    width : 宽
    height : 高
    返回值 : Bitmap

    使用示例:

    ImageView mImgA_A = (ImageView) findViewById(R.id.img_a_a);
    ImageView mBaseView = (ImageView) findViewById(R.id.img_base1);
    
    Bitmap baseBitmap = ((BitmapDrawable)mBaseView.getDrawable()).getBitmap();
    Bitmap clipBitmap = CImageUtils.instance(this).cropToBitmap(baseBitmap,320,320);
    mImgA_A.setImageBitmap(clipBitmap);
    

Demo 工程编译运行

  • 在git中执行下面命令clone工程到本地:
    git clone git@github.com:CNCFOX/ImageViewClip.git

  • 用Android studio 打开工程

  • 打开 Gradle 找到 :ivcliplib ,展开other文件夹,找到ndkCleanndkBuild分别执行,然后运行项目。
    如下图:

    :ivcliplib
    ndkClean 和 ndkBuild

相关文章

  • Android 图片人脸识别剪切

    场景 在开发中我们经常需要对图片以人脸为中心进行剪切并显示,这时就需要下面这个工具了。 实现效果 Demo及工程地...

  • Android实现人脸识别(人脸检测)初识

    title: Android实现人脸识别(人脸检测)初识categories: Androidtags: 人脸识别...

  • wrs-arcface虹软人脸识别

    前言 虹软人脸识别组件,支持活体识别、离线识别、图片人脸特征识别、图片是否同一人对比、相机人脸识别或对比 功能 支...

  • 使用CoreImage人脸识别初试

    一 静态图片的人脸识别静态图片的人脸识别比较简单,直接看代码注释即可 二 相机实时的人脸识别,分步骤如下:(...

  • 人脸识别技术

    人脸识别技术 (一) —— 基于CoreImage实现对静止图片中人脸的识别人脸识别技术 (二) —— 基于Cor...

  • Android人脸识别

    人脸注册和识别 链接 Android人脸识别开发入门--基于虹软免费SDK实现

  • 人脸识别

    图片人脸检测——OpenCV版(二) 图片人脸检测——Dlib版(四) 人脸识别之人脸对齐(一)--定义及作用

  • iOS 人脸识别Demo

    最近尝试了下苹果中关于人脸识别的API 尝试着写了几个demo: 静态图片人脸识别 动态识别人脸OC版 动态识别人...

  • Android园区部队人脸识别源码门禁项目讲解

    Android园区部队人脸识别源码门禁项目讲解 这边搞人脸识别相关项目有一段时间,今天抽时间讲述一个经典的人脸识别...

  • Android原生人脸识别Camera2+FaceDetecto

    title: Android原生人脸识别Camera2+FaceDetector 快速实现人脸跟踪categori...

网友评论

    本文标题:Android 图片人脸识别剪切

    本文链接:https://www.haomeiwen.com/subject/eyplqxtx.html