Note that there are some explanatory texts on larger screens.

plurals
  1. PODetect faces on an image captured in Android OpenCV java
    primarykey
    data
    text
    <p>When touch on the screen, this method is invoked, highgui.imwrite is suppose to overwrite the previous store into sdcard method.</p> <pre><code> public boolean onTouch(View v, MotionEvent event) { Log.i(TAG,"onTouch event"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss"); String currentDateandTime = sdf.format(new Date()); String fileName = Environment.getExternalStorageDirectory().getPath() + "/sample_picture_" + currentDateandTime + ".jpg"; mOpenCvCameraView.takePicture(fileName); Toast.makeText(this, fileName + " saved", Toast.LENGTH_SHORT).show(); Mat a = Highgui.imread(fileName); MatOfRect faceDetections = new MatOfRect(); if (mDetectorType == JAVA_DETECTOR) { if (mJavaDetector != null) mJavaDetector.detectMultiScale(a, faceDetections); } else if (mDetectorType == NATIVE_DETECTOR) { if (mNativeDetector != null) mNativeDetector.detect(mGray, faceDetections); } else { Log.e(TAG, "Detection method is not selected!"); } for (Rect rect : faceDetections.toArray()){ Core.rectangle(a, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height), new Scalar(0, 255, 0)); Boolean bool = null; bool = Highgui.imwrite(fileName,a); if (bool == true) Log.d(TAG, "SUCCESS writing image to external storage"); else Log.d(TAG, "Fail writing image to external storage"); } return false; } </code></pre> <p>Then this method will create fileName for storing in external storage and takes the picture.</p> <pre><code>public void takePicture(final String fileName) { Log.i(TAG, "Taking picture"); this.mPictureFileName = fileName; // Postview and jpeg are sent in the same buffers if the queue is not empty when performing a capture. // Clear up buffers to avoid mCamera.takePicture to be stuck because of a memory issue mCamera.setPreviewCallback(null); // PictureCallback is implemented by the current class mCamera.takePicture(null, null, this); } </code></pre> <p>This method takes bytes array and store into sdcard.</p> <pre><code> public void onPictureTaken(byte[] data, Camera camera) { Log.i(TAG, "Saving a bitmap to file"); // The camera preview was automatically stopped. Start it again. mCamera.startPreview(); //... mCamera.setPreviewCallback(this); // Write the image in a file (in jpeg format) try { FileOutputStream fos = new FileOutputStream(mPictureFileName); fos.write(data); fos.close(); } catch (java.io.IOException e) { Log.e("PictureDemo", "Exception in photoCallback", e); } } </code></pre> <p>Now I believe I have converted to type Mat with highgui.imread(directory). But now I want to able to detect faces on that image with rectangle then store the image in sdcard using high.imwrite but when i open the image it does not have the rectangle on faces. Any idea or suggestions on what Im doing wrong? Any reply is greatly appreciated. Thank you. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload