我正在尝试检测自动拍摄的照片上的脸,但它不起作用。在我捕获图片后,我将其发送到ImageView,然后我尝试从他们的,并进行面部检测。但是有错误,位图需要R.drawble,我给R.id.我不知道该用什么 我是新手
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form>
<select>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>
<br>
<input type="text">
<button type="button">Get values</button>
</form>
}
这是我拍摄照片的课程
public class MainActivity extends AppCompatActivity {
public static int cameraID = 0;
public static boolean isBlack = true;
public static ImageView image;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
image = (ImageView) findViewById(R.id.imgView);
Button btfront=(Button) findViewById(R.id.frontButton);
btfront.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v) {
onFrontClick(v);
facedetection(v);
}
});
}
public void onFrontClick(View v){
RadioButton rdbBlack = (RadioButton) findViewById(R.id.rdb_black);
if(rdbBlack.isChecked()){
isBlack = true;
}else{
isBlack = false;
}
cameraID = 1;
Intent i = new Intent(MainActivity.this,CameraView.class);
startActivityForResult(i, 999);
}
public void onBackClick(View v){
RadioButton rdbBlack = (RadioButton) findViewById(R.id.rdb_black);
if(rdbBlack.isChecked()){
isBlack = true;
}else{
isBlack = false;
}
cameraID = 0;
Intent i = new Intent(MainActivity.this,CameraView.class);
startActivityForResult(i, 999);
}
public void facedetection(View v)
{
BitmapFactory.Options options = new BitmapFactory.Options();
options.inMutable=true;
Bitmap myBitmap = BitmapFactory.decodeResource(
getApplicationContext().getResources(),
R.id.imgView,
options);
Paint myRectPaint = new Paint();
myRectPaint.setStrokeWidth(5);
myRectPaint.setColor(Color.RED);
myRectPaint.setStyle(Paint.Style.STROKE);
Bitmap tempBitmap = Bitmap.createBitmap(myBitmap.getWidth(), myBitmap.getHeight(), Bitmap.Config.RGB_565);
Canvas tempCanvas = new Canvas(tempBitmap);
tempCanvas.drawBitmap(myBitmap, 0, 0, null);
FaceDetector faceDetector = new
FaceDetector.Builder(getApplicationContext()).setTrackingEnabled(false)
.build();
if(!faceDetector.isOperational()){
new AlertDialog.Builder(v.getContext()).setMessage("Could not set up the face detector!").show();
return;
}
Frame frame = new Frame.Builder().setBitmap(myBitmap).build();
SparseArray<Face> faces = faceDetector.detect(frame);
for(int j=0; j<faces.size(); j++) {
Face thisFace = faces.valueAt(j);
float x1 = thisFace.getPosition().x;
float y1 = thisFace.getPosition().y;
float x2 = x1 + thisFace.getWidth();
float y2 = y1 + thisFace.getHeight();
tempCanvas.drawRoundRect(new RectF(x1, y1, x2, y2), 2, 2, myRectPaint);
}
image.setImageDrawable(new BitmapDrawable(getResources(),tempBitmap));
}
答案 0 :(得分:0)
@Lefteris如果您正在查看转换
ContextCompat.getDrawable(context, android.R.drawable.ic_dialog_email)