Note that there are some explanatory texts on larger screens.

plurals
  1. POvary slow frame rate when calling HoughCircles() method from onCameraFrame, OpenCV, Android/Java
    primarykey
    data
    text
    <p>extremely slow frame rates when using the openCV Java method in android for detecting circular shaped objects in images</p> <pre><code> Imgproc.HoughCircles(mGray, circles, Imgproc.CV_HOUGH_GRADIENT, 1, 50); </code></pre> <p>when i remove this method it runs fast, but after adding this method inside of this callback</p> <pre><code> public Mat onCameraFrame(final CvCameraViewFrame inputFrame) { </code></pre> <p>the frame rate slows to 1 to 2 frames per second, I don't understand why it gets so slow, i tried putting this method in a separate thread and it would not help, the only thing that worked is to use a counter and and an if statement to run the method every 10 frames.</p> <p>in the OpenCV examples there is a sample project called face detection and it has both a native C++ and Java camera versions and they both are vary fast, how is it possible that when I use similar code I get this slow constipated action from OpenCV?</p> <p>is there something i am doing wrong here? In the face detection project from openCV examples they take every frame and they don't launch a separate thread. how do I fix this problem and make my code run fast like the sample projects in OpenCV?</p> <p>in a different project I am also having the same problem of slow frame rate, in this practice project where I am not using openCV, it is just the android Camera class only, in that I am taking the image from the onPreviewFrame(byte[] data, Camera camera) method and doing some light processing like converting the YUV format from the byte array into a bitmap and putting that into another view on the same screen as the camera view, and the result is vary slow frame rate.</p> <p>EDIT: In some additional experimentation I added the Imgproc.HoughCircles() method to the OpenCV face Detection sample project. putting this method inside the onCameraFrame method of the java detector.</p> <p>the result is the same as in my project, it became vary slow. so the HoughCircles method probably takes more processing power than the face detection method CascadeClassifier.detectMultiScale(), however that does not explain the fact I watched other circle detection projects on youTube and in their videos the frame rate is not slowed down. that is why I think there is something wrong with what I am doing.</p> <p>here is a sample of the code I am using</p> <pre><code>public class CircleActivity extends Activity implements CvCameraViewListener2 { Mat mRgba; Mat mGray; File mCascadeFile; CascadeClassifier mJavaDetector; CameraBridgeViewBase mOpenCvCameraView; LinearLayout linearLayoutOne; ImageView imageViewOne; int counter = 0; private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) { @Override public void onManagerConnected(int status) { switch (status) { case LoaderCallbackInterface.SUCCESS: { Log.i("OPENCV", "OpenCV loaded successfully"); mOpenCvCameraView.enableView(); } break; default: { super.onManagerConnected(status); } break; } } }; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { if (!OpenCVLoader.initDebug()) { // Handle initialization error } super.onCreate(savedInstanceState); setContentView(R.layout.activity_coffee); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.fd_activity_surface_view); mOpenCvCameraView.setCvCameraViewListener(this); } @Override public void onPause() { super.onPause(); if (mOpenCvCameraView != null) mOpenCvCameraView.disableView(); } @Override public void onResume() { super.onResume(); OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_3, this, mLoaderCallback); } public void onDestroy() { super.onDestroy(); mOpenCvCameraView.disableView(); } public void onCameraViewStarted(int width, int height) { mGray = new Mat(); mRgba = new Mat(); } public void onCameraViewStopped() { mGray.release(); mRgba.release(); } public Mat onCameraFrame(final CvCameraViewFrame inputFrame) { mRgba = inputFrame.rgba(); mGray = inputFrame.gray(); if(counter == 9) { MatOfRect circles = new MatOfRect(); Imgproc.HoughCircles(mGray, circles, Imgproc.CV_HOUGH_GRADIENT, 1, 50); // returns number of circular objects found Log.e("circle check", "circles.cols() " + circles.cols()); } counterAdder(); return mRgba; } // end oncamera frame public void counterAdder() { if (counter &gt; 10) { counter = 0; } counter++; } } </code></pre>
    singulars
    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.
 

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