我想獲得幀圖像,同時採用最新的Android臉部偵測移動視覺API來處理。如何從灰度字節緩衝區圖像創建位圖?
所以我創建的自定義探測器獲得幀,並試圖調用getBitmap()方法,但它爲空,所以我訪問幀的灰度級數據。有沒有辦法從它創建位圖或類似的圖像持有人類?
public class CustomFaceDetector extends Detector<Face> {
private Detector<Face> mDelegate;
public CustomFaceDetector(Detector<Face> delegate) {
mDelegate = delegate;
}
public SparseArray<Face> detect(Frame frame) {
ByteBuffer byteBuffer = frame.getGrayscaleImageData();
byte[] bytes = byteBuffer.array();
int w = frame.getMetadata().getWidth();
int h = frame.getMetadata().getHeight();
// Byte array to Bitmap here
return mDelegate.detect(frame);
}
public boolean isOperational() {
return mDelegate.isOperational();
}
public boolean setFocus(int id) {
return mDelegate.setFocus(id);
}}
該幀沒有位圖數據,因爲它直接來自相機。來自攝像機的圖像格式爲NV21:http://developer.android.com/reference/android/graphics/ImageFormat.html#NV21 – pm0733464