Ask Your Question

Ramandaleo's profile - activity

2014-06-23 04:10:45 -0600 commented question Adding Trackbar on jni part of Android OpenCV

Thank you berak

2014-06-22 11:43:34 -0600 asked a question Adding Trackbar on jni part of Android OpenCV

Hello,

I am new to Android OpenCV. I am trying to detect circles using Hough Algorithm on Android phone. I have edited jni part of Android OpenCv sample code(OpenCv Tutorial2 - Mixed Processing). I am able to detect circles on myy Android. Now i want to add trackbar for caliberation purpose to change the value of param1 and param2 in hough function.

void HoughCircles(InputArray image, OutputArray circles, int method, double dp, double minDist, double param1, double param2, int minRadius=0, int maxRadius=0);

Here is my code for circle detection:

include<jni.h>

include <opencv2 core="" core.hpp="">

include <opencv2 imgproc="" imgproc.hpp="">

include <opencv2 highgui="" highgui.hpp="">

include <opencv2 features2d="" features2d.hpp="">

include <vector>

include <iostream>

include <stdio.h>

define w 400

using namespace std; using namespace cv;

/// Global Variables const int alpha_slider_max = 100; int alpha_slider; double alpha; double beta;

/// Matrices to store images Mat src1; Mat dst;

/** * @function on_trackbar * @brief Callback for trackbar */

int resizefactor = 5;

Point center1(1200,100);

void drawcircle(Mat mRgb){ circle( mRgb, center1, w/12,Scalar( 0, 0, 255 ),3, 8 );

Point textPos(1140, 170); std::ostringstream oss2; oss2 << "Ref.r:" <<w 12="" ;="" puttext(mrgb,="" oss2.str(),="" textpos,="" font_hershey_simplex,="" 1.0,="" scalar(0,0,255),="" 1,8,="" false);="" }<="" p="">

/** * @function on_trackbar * @brief Callback for trackbar */

void convertHough(Mat mRgb,Mat image, int rmin, int rmax){

      vector<Vec3f> circles;
      HoughCircles( image, circles, CV_HOUGH_GRADIENT, 2, image.rows/8, 60, 40, rmin, rmax );

         Point offset(-resizefactor, -resizefactor);


         for (int n = 0; n < circles.size(); n++) {
        Point center(cvRound(((double)circles[n][0]))*5, cvRound(((double)circles[n][1]))*5);
        int radius = cvRound(((double)circles[n][2])*5);

        // Draw circle center
        circle(mRgb, center + offset, 3, Scalar(0,0,0), -1, 8, 0);
        circle(mRgb, center, 3, Scalar(255,255,0), -1, 8, 0);

        // Draw circle outline
        circle(mRgb, center + offset, radius, Scalar(0,0,0), 3, 8, 0);
        circle(mRgb, center, radius, Scalar(255,255,0), 3, 8, 0);

          Point textPos(50, 50);
          std::ostringstream oss2;
          oss2 << "Anzahl Kreise:" << circles.size();
          putText(mRgb,
                  oss2.str(),
                  textPos,
                  FONT_HERSHEY_SIMPLEX,
                  1.0,
                  Scalar(0,0,0),
                  1,8,
                  false);


               for(size_t m = 0; m< circles.size(); m++){

                  Point textPos(101, 101+m*60);
                  std::ostringstream oss2;
                  oss2 << "x:" << cvRound(((double)circles[m][0]))*5 << "y:" << cvRound(((double)circles[m][1]))*5;
                  putText(mRgb,
                          oss2.str(),
                          textPos,
                          FONT_HERSHEY_SIMPLEX,
                          1.0,
                          Scalar(0,0,0),
                          1,8,
                          false);
               }

}

}

extern "C" { JNIEXPORT void JNICALL Java_org_opencv_samples_tutorial2_Tutorial2Activity_FindFeatures(JNIEnv*, jobject, jlong addrGray, jlong addrRgba);

JNIEXPORT void JNICALL Java_org_opencv_samples_tutorial2_Tutorial2Activity_FindFeatures(JNIEnv, jobject, jlong addrGray, jlong addrRgba) { Mat& mGr = *(Mat)addrGray; Mat& mRgb = (Mat)addrRgba;

drawcircle(mRgb);

        Mat greyimagesmall;
        int resizefactor = 5;


        resize(mGr, greyimagesmall, Size(mGr.cols/resizefactor, mGr.rows/resizefactor));

        /********************
         * Trackbar Function
         *********************/

        /****************************
         * End of Trackbar function
         ****************************/



        // Smooth the image so that not too many circles are detected
        GaussianBlur(greyimagesmall, greyimagesmall, Size(5,5), 2, 2);



        convertHough(mRgb,greyimagesmall, greyimagesmall.cols/50, greyimagesmall.cols/30);

// vector<keypoint> v; /* FastFeatureDetector detector(50); detector.detect(mGr, v); for( unsigned int i = 0; i < v.size(); i++ ) { const KeyPoint& kp ... (more)