如何检测图像中的全身

时间:2018-09-02 11:13:44

标签: android opencv detection haar-classifier

如何在imageview中的图像上使用haar级联全身检测?

基本上,我想做的是结合以下代码,并制作一个应用程序,使用户可以使用相机应用程序捕获图像并在活动中显示图像。然后,该应用通过用矩形突出显示一个人的整个身体来检测该人的整个身体。

这是我的代码,用于捕获图像,然后将其显示在活动中:

const elementsWithDisplayBlockProperty = []
document.querySelectorAll("body *").forEach(element => {
    window.getComputedStyle(element).getPropertyValue("display") === "block" && elementsWithDisplayBlockProperty.push(element)
})

console.log(elementsWithDisplayBlockProperty) // result

以及用于全身检测(实时)的代码:

package com.hehe.trumpcard;

import android.content.Intent;
import android.graphics.Bitmap;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {

private ImageView im;
private Button b;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    im = (ImageView) findViewById(R.id.imageid); //Your image View
    b = (Button) findViewById(R.id.buttonid); // your Button

    b.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent img = new Intent(); //Your Intent
            img.setAction(MediaStore.ACTION_IMAGE_CAPTURE); //the intents action to capture the image
            startActivityForResult(img, 1);//start the activity adding any code .1 in this example
        }

    });
}

protected void onActivityResult(int requestCode,int resultCode,Intent data){
    super.onActivityResult(requestCode,resultCode,data);//method retrieves the requestCode , its result and the data containing the pic from system
    if(requestCode==1&&resultCode==RESULT_OK){
        Bitmap photo = (Bitmap)data.getExtras().get("data"); //get data and casts it into Bitmap photo
        im.setImageBitmap(photo);// set photo to imageView
    }

}
}

如何合并这两个代码?预先感谢!

0 个答案:

没有答案