Ask Your Question

Mehmet Taha Meral's profile - activity

2018-11-23 07:14:36 -0500 received badge  Popular Question (source)
2017-09-11 15:27:21 -0500 received badge  Student (source)
2015-08-26 09:07:11 -0500 answered a question Camera Preview slow on Android OpenCV +possible bottleneck found

I' ve faced this problem either. I' ve tried to decrease the camera resolution with mOpenCvCameraView.setMaxFrameSize(1280, 720);

However it is still slow. I' ve been trying to work parallel with Threads, but it is still 3.5FPS.

public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
    carrierMat = inputFrame.gray();
    Thread thread = new Thread(new MultThread(carrierMat, this));
    try {
    } catch (InterruptedException e) {
    return carrierMat;

My MultThread class is just like this

public class MultThread implements Runnable {
private Mat source;
private Context context;

public MultThread(Mat source, Context context) {
    this.source = source;
    this.context = context;

public void run() {
    //output = General.Threshold(source);
    int x = General.MSERP(source);
    Log.i("MtMTxtDtc:Main","x: " + x);
    if (x > 10){
        ((Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE)).vibrate(500);


2015-08-21 11:54:17 -0500 asked a question How can I draw rectangle with MatOfKeyPoint for Text Detection | Java

Hi guys,

I' ve been working on real time text detection and recognition with OpenCV4Android. Recognition part is totally completed. However, I have to ask question about text detection. I' m using the MSER FeatureDetector for detection text.

This is the real time and calling the method part:

public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
    carrierMat = inputFrame.gray();
    carrierMat = General.MSER(carrierMat);
    return carrierMat;

And this is the basic MSER implementation:

private static FeatureDetector fd = FeatureDetector.create(FeatureDetector.MSER);
private static MatOfKeyPoint mokp = new MatOfKeyPoint();
private static Mat edges = new Mat();

public static Mat MSER(Mat mat) {
    //for mask
    Imgproc.Canny(mat, edges, 400, 450);
    fd.detect(mat, mokp, edges);
    //for drawing keypoints
    Features2d.drawKeypoints(mat, mokp, mat);
    return mat;

It works fine for finding text with edges mask.

I would like to draw a rectangles for clusters like this: image description

or this

image description

You can assume that I have the right points.

As you can see, fd.detect() method is returning a MatOfKeyPoint. Hence I' ve tried this method for drawing rectangle:

public static Mat MSER_(Mat mat) {
    fd.detect(mat, mokp);
    KeyPoint[] refKp = mokp.toArray();
    Point[] refPts = new Point[refKp.length];

    for (int i = 0; i < refKp.length; i++) {
        refPts[i] = refKp[i].pt;
    MatOfPoint2f refMatPt = new MatOfPoint2f(refPts);
    MatOfPoint2f approxCurve = new MatOfPoint2f();

    //Processing on mMOP2f1 which is in type MatOfPoint2f
    double approxDistance = Imgproc.arcLength(refMatPt, true) * 0.02;
    Imgproc.approxPolyDP(refMatPt, approxCurve, approxDistance, true);

    //Convert back to MatOfPoint
    MatOfPoint points = new MatOfPoint(approxCurve.toArray());
    // Get bounding rect
    Rect rect = Imgproc.boundingRect(points);
    // draw enclosing rectangle (all same color, but you could use variable i to make them unique)
    Imgproc.rectangle(mat, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height), Detect_Color_, 5);
    //Features2d.drawKeypoints(mat, mokp, mat);
    return mat;

But when I was trying to Imgproc.arcLength() method, it suddenly stopped. I gave a random approxDistance value for Imgproc.approxPolyDP() method like 0.1, it doesn' t work really efficiently.

So how can I draw rectangle for detected text?