2015-01-21 26 views
0

你好,Android程序员在这里,请检查我的代码,填写关于裁剪检测到的图像的参数。什么应该是我的int x,y在我的裁剪侦测脸上?

我不知道应该把什么值放在android中使用createBitmap(Bitmapsource,x,y,width,height). 检测到的面部裁剪参数如何获得一些整数的x和y来填充位图函数中的参数。

public Mat onCameraFrame(CvCameraViewFrame inputFrame) { 

     mRgba = inputFrame.rgba(); 
     mGray = inputFrame.gray(); 

     if (mAbsoluteFaceSize == 0) { 
      int height = mGray.rows(); 
      if (Math.round(height * mRelativeFaceSize) > 0) { 
       mAbsoluteFaceSize = Math.round(height * mRelativeFaceSize); 
      } 
      mNativeDetector.setMinFaceSize(mAbsoluteFaceSize); 
     } 

     MatOfRect faces = new MatOfRect(); 

     if (mDetectorType == JAVA_DETECTOR) { 
      if (mJavaDetector != null) 
       mJavaDetector.detectMultiScale(mGray, faces, 1.1, 2, 2, // TODO: objdetect.CV_HAAR_SCALE_IMAGE 
         new Size(mAbsoluteFaceSize, mAbsoluteFaceSize), new Size()); 
     } 
     else if (mDetectorType == NATIVE_DETECTOR) { 
      if (mNativeDetector != null) 
       mNativeDetector.detect(mGray, faces); 
     } 
     else { 
      Log.e(TAG, "Detection method is not selected!"); 
     } 

     Rect[] facesArray = faces.toArray(); 

     for (int i = 0; i < facesArray.length; i++) 
      Core.rectangle(mRgba, facesArray[i].tl(), facesArray[i].br(), FACE_RECT_COLOR, 3); 

     //crop 

     //crop 
     viewWidth = part1.getMeasuredWidth(); 
     viewHeight = part1.getMeasuredHeight(); 
     //create the bitmap 
     bmp = Bitmap.createBitmap(mRgba.cols(), mRgba.rows(), Bitmap.Config.ARGB_8888); 
     Resizebmp = Bitmap.createBitmap(bmp, x, y, viewWidth, viewHeight); 


     try { 
      Utils.matToBitmap(mRgba, bmp); 

     } catch(Exception e) { 
      Log.e(TAG, "Utils.matToBitmap() throws an exception: " + e.getMessage()); 
      bmp.recycle(); 
      bmp = null; 
     } 


     return mRgba; 
    } 

回答

0

纠正我,如果我错了。你的意思是你已经在一个大的位图中检测到了脸部,并且你想将脸部裁剪到一个更小的位图上? 例如,您有一个640 x 480位图,并且您发现矩形内部的脸部位于左上方的x1,y1和右下方的x2,y2。那么它应该是这样的:

resizeBmp = Bitmap.createBitmap(bmp, x1, y1, x2 - x1, y2 - y1); 
+0

我怎样才能得到我的x和y值?通过脸部的矩形 – user3847358 2015-01-22 02:27:23