Ask Your Question

siline's profile - activity

2017-11-10 06:16:33 -0600 received badge  Popular Question (source)
2017-05-17 10:27:19 -0600 received badge  Student (source)
2016-12-03 06:46:21 -0600 commented question fourier descriptor in opencv

So how can i use Fourier to learn images

2016-12-03 04:55:49 -0600 commented question fourier descriptor in opencv

I would use fourier to construct a descripter used as a feature for machine learning (KNN)

2016-12-02 09:11:05 -0600 commented question fourier descriptor in opencv

I should change all the type CV_64FC1 and CV_64FC1 to CV_32F or only for complexI and complexI2 ?

2016-12-02 08:28:52 -0600 commented question fourier descriptor in opencv

yes, it still the same error . i think that the logical type is CV_64FC2 because we need complexe number but i don't guess the error

2016-12-02 08:05:05 -0600 commented question fourier descriptor in opencv

I tried CV_8UC1 , CV_16S

2016-12-02 06:25:02 -0600 commented question fourier descriptor in opencv

I tried to change the format but the error persist

2016-12-02 05:41:50 -0600 received badge  Enthusiast
2016-12-01 15:48:52 -0600 asked a question fourier descriptor in opencv

I tried to implement fourier descriptor to use it in machine learning algorithm but i got this error OpenCV Error: Assertion failed (type == CV_32FC1 || type == CV_32FC2 || type == CV_64FC1 || type == CV_64FC2) in void cv::dft(cv::InputArray, cv::OutputArray, int, int), file /home/maksim/workspace/android-pack/opencv/modules/core/src/dxt.cpp, line 2506

This is my code:

            Mat trainData = new Mat();
    Mat train_labels = new Mat();


    String Newligne=System.getProperty("line.separator");


    for (int i = 0; i <48; i++) {
        String path1 = Environment.getExternalStorageDirectory().toString()
                + "/Pictures/images/" + "a"+i + ".jpg";


        Mat img = Imgcodecs.imread(path1);
        Log.i(TAG, "error" + i + img.empty());
        img.convertTo(img, CvType.CV_32FC1);
        Mat secondImage = new Mat(img.rows(), img.cols(), CvType.CV_64FC1);
        img.convertTo(secondImage, CvType.CV_64FC1);

        int m = Core.getOptimalDFTSize(img.rows());
        int n = Core.getOptimalDFTSize(img.cols()); // on the border
        // add zero values Imgproc.copyMakeBorder(image1, padded, 0, m - image1.rows(), 0, n

        Mat padded = new Mat(new Size(n, m), CvType.CV_64FC1); // expand input
        // image to
        // optimal size

        Core.copyMakeBorder(secondImage, padded, 0, m - secondImage.rows(), 0,
                n - secondImage.cols(), Core.BORDER_CONSTANT);

        List<Mat> planes = new ArrayList<Mat>();
        planes.add(padded);
        planes.add(Mat.zeros(padded.rows(), padded.cols(), CvType.CV_64FC1));

        Mat complexI = Mat.zeros(padded.rows(), padded.cols(), CvType.CV_64FC2);

        Mat complexI2 = Mat
                .zeros(padded.rows(), padded.cols(), CvType.CV_64FC2);

        Core.merge(planes, complexI); // Add to the expanded another plane with
        // zeros

        Core.dft(complexI, complexI2); // this way the result may fit in the
        // source matrix

        // compute the magnitude and switch to logarithmic scale
        // => log(1 + sqrt(Re(DFT(I))^2 + Im(DFT(I))^2))
        Core.split(complexI2, planes); // planes[0] = Re(DFT(I), planes[1] =
        // Im(DFT(I))

        Mat mag = new Mat(planes.get(0).size(), planes.get(0).type());

        Core.magnitude(planes.get(0), planes.get(1), mag);// planes[0]
        // =
        // magnitude

        Mat magI = mag;
        Mat magI2 = new Mat(magI.size(), magI.type());
        Mat magI3 = new Mat(magI.size(), magI.type());
        Mat magI4 = new Mat(magI.size(), magI.type());
        Mat magI5 = new Mat(magI.size(), magI.type());

        Core.add(magI, Mat.ones(padded.rows(), padded.cols(), CvType.CV_64FC1),
                magI2); // switch to logarithmic scale
        Core.log(magI2, magI3);

        Mat crop = new Mat(magI3, new Rect(0, 0, magI3.cols() & -2,
                magI3.rows() & -2));

        magI4 = crop.clone();

        // rearrange the quadrants of Fourier image so that the origin is at the
        // image center
        int cx = magI4.cols() / 2;
        int cy = magI4.rows() / 2;

        Rect q0Rect = new Rect(0, 0, cx, cy);
        Rect q1Rect = new Rect(cx, 0, cx, cy);
        Rect q2Rect = new Rect(0, cy, cx, cy);
        Rect q3Rect = new Rect(cx, cy, cx, cy);

        Mat q0 = new Mat(magI4, q0Rect); // Top-Left - Create a ROI per quadrant
        Mat q1 = new Mat(magI4, q1Rect); // Top-Right
        Mat q2 = new Mat(magI4, q2Rect); // Bottom-Left
        Mat q3 = new Mat(magI4, q3Rect); // Bottom-Right

        Mat tmp = new Mat(); // swap quadrants (Top-Left with Bottom-Right)
        q0.copyTo(tmp);
        q3.copyTo(q0);
        tmp.copyTo(q3);

        q1.copyTo(tmp); // swap quadrant (Top-Right with Bottom-Left)
        q2.copyTo(q1);
        tmp.copyTo(q2);

        Core.normalize(magI4, magI5, 0 ...
(more)
2016-05-28 06:07:32 -0600 commented question Android svm implementation error

I have to recognize letters in an image .so i try to submat each letter from text extracted from image taken by phone camera and then i shoud recognize each letter (i can't use ocr because image is a latin manuscrit so letters aren't very clear) by refering to svm algorithm for opencv.So if i understand i should create for each letter a class ? but i don't know how

2016-05-28 05:57:52 -0600 commented question Android svm implementation error

In my application i should get images from data base and try to train them using opencv svm .Really i don't understand how to change i and how put my training data in classes

2016-05-28 05:26:44 -0600 commented question Android svm implementation error

when i change type of label i got this error: 05-28 11:25:30.378: E/cv::error()(9388): OpenCV Error: Insufficient memory (Failed to allocate 1128195000 bytes) in void* cv::OutOfMemoryError(size_t), file /home/maksim/workspace/android-pack/opencv/modules/core/src/alloc.cpp, line 52 05-28 11:25:30.378: E/cv::error()(9388): OpenCV Error: Assertion failed (u != 0) in void cv::Mat::create(int, const int, int), file /home/maksim/workspace/android-pack/opencv/modules/core/src/matrix.cpp, line 411 05-28 11:25:30.388: E/org.opencv.ml(9388): ml::train_10() caught cv::Exception: /home/maksim/workspace/android-pack/opencv/modules/core/src/matrix.cpp:411: error: (-215) u != 0 in function void cv::Mat::create(int, const int, int)

2016-05-28 05:06:53 -0600 asked a question Android svm implementation error

I tried to implement svm in my android application but when i run my application i get errors.

        // Creating Training Data
            Mat trainData = new Mat();
        Mat train_labels = new Mat();


            for (int i = 0; i <549; i++) {
            String path = Environment.getExternalStorageDirectory().toString()
                    + "/Pictures/train/" + i + ".png";

            Mat img = Imgcodecs.imread(path);

            Log.i(TAG,"error"+i+img.empty());

            img.convertTo(img, CvType.CV_32FC1); // Convert to float
            Size dsize = new Size(25, 25);
            Imgproc.resize(img, img, dsize);

            img.convertTo(img, CvType.CV_32FC1);
            Mat imgResized = img.reshape(1, 1); // make continuous

            trainData.push_back(imgResized);
            // add 1 item
            train_labels
                    .push_back(new Mat(1, 1, CvType.CV_32FC1, new Scalar(i)));

        }

        Mat response = new Mat();
        Mat tmp;
        tmp = train_labels.reshape(1, 1); // make continuous
        tmp.convertTo(response, CvType.CV_32FC1); // Convert to float
         SVM svm = SVM.create();
            TermCriteria criteria = new TermCriteria(TermCriteria.EPS + TermCriteria.MAX_ITER,100,0.1);
            svm.setKernel(SVM.LINEAR);
            svm.setType(SVM.C_SVC);
            svm.setGamma(0.5);
            svm.setNu(0.5);
            svm.setC(1);
            svm.setTermCriteria(criteria);
            svm.train(trainData, Ml.ROW_SAMPLE,train_labels);

        // For Storing training data


        File datasetFile = new File(Environment.getExternalStoragePublicDirectory(
                Environment.DIRECTORY_DOWNLOADS), "dataset.xml");
        svm.save(datasetFile.getAbsolutePath());

And this is the error:

05-28 11:05:01.921: E/cv::error()(2252): OpenCV Error: Bad argument (in the case of classification problem the responses must be categorical; either specify varType when creating TrainData, or pass integer responses) in virtual bool cv::ml::SVMImpl::train(const cv::Ptr<cv::ml::traindata>&, int), file /home/maksim/workspace/android-pack/opencv/modules/ml/src/svm.cpp, line 1610 05-28 11:05:01.931: E/org.opencv.ml(2252): ml::train_10() caught cv::Exception: /home/maksim/workspace/android-pack/opencv/modules/ml/src/svm.cpp:1610: error: (-5) in the case of classification problem the responses must be categorical; either specify varType when creating TrainData, or pass integer responses in function virtual bool cv::ml::SVMImpl::train(const cv::Ptr<cv::ml::traindata>&, int)

2016-04-19 03:26:22 -0600 commented question which method is better SVM,KNN or neural network for letters recognition

@sturkmen My picture also is not clear to apply tesseract (Manuscrit latin).So i am obliged to use training data but i don't know which method is the best.

2016-04-18 14:58:40 -0600 asked a question which method is better SVM,KNN or neural network for letters recognition

i have to recognize letters in a picture taken with android camera and i should use machine learning .I can't choose the best method .

2016-04-15 06:59:33 -0600 asked a question How to put a label of type string in a matrix (KNN)

This line put a label for a trainData mat

train_labels.push_back(new Mat (1,1,CvType.CV_32FC1,new Scalar(i)))

I would put a string label instead of a float label .is it possible ?

2016-04-04 10:49:06 -0600 received badge  Editor (source)
2016-04-04 10:47:41 -0600 asked a question Template Matching with Multiple Objects for android and java using opencv

I am tring to match multiple object using a single template .I succed to match only one object and this is the code but i don't know how to match multiple objects .I find a lot of resources but they are in c++ language and i need java code

   public class MainActivity extends Activity {

  Button button;
  ImageView imageView;
  ImageView n3;

File cacheDir;

protected static final String TAG = "OpenCV";

private BaseLoaderCallback mLoaderCallBack = new BaseLoaderCallback(this) {
    public void onManagerConnected(int status) {
        switch (status) {
        case LoaderCallbackInterface.SUCCESS:
            Log.i(TAG, "Open CV loaded successfully");
            break;

        default:
            super.onManagerConnected(status);
            break;
        }
    };
};

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    addListenerOnButton();
    initDir();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public void onResume() {
    super.onResume();
    OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_1_0, this,mLoaderCallBack);

}

// ADDED THIS: to create/initialize external file
// Be sure write permissions is enabled in the manifest file
// ie add: <uses-permission android:name= "android.permission.WRITE_EXTERNAL_STORAGE"/>
public void initDir() {
    if (android.os.Environment.getExternalStorageState().equals(
            android.os.Environment.MEDIA_MOUNTED)) {
        cacheDir = new File(
                android.os.Environment.getExternalStorageDirectory(),"LazyList");

        if (!cacheDir.exists()) {
            cacheDir.mkdirs();
        }
    }
}

// added this to simplify creating full file path
public String getFileAbsPath(String fileName) {
    File f = new File(cacheDir, fileName);
    return f.getAbsolutePath();
}

public void addListenerOnButton() {

    imageView = (ImageView) findViewById(R.id.imageView1);
    n3 = (ImageView) findViewById(R.id.imageView2);

    button = (Button) findViewById(R.id.button1);
    button.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            String infile = "/storage/emulated/0/DCIM/Camera/n2.png";
            String tp = "/storage/emulated/0/DCIM/Camera/n1.png";
            String outFile = "/storage/emulated/0/DCIM/Camera/n3.png";

            try {
                matchTemplate(infile, tp, outFile, Imgproc.TM_CCOEFF);
                Bitmap bm = BitmapFactory.decodeFile(outFile);
                n3.setImageBitmap(bm);
            } catch (Exception e) {
                // TODO: handle exception
                e.printStackTrace();
            }
        }

    });

}

public Mat matchTemplate(String inFile, String templateFile,String outFile, int match_method) {
    Log.i(TAG, "Running Template Matching");

    Mat img = Imgcodecs.imread(inFile);
    Mat templ = Imgcodecs.imread(templateFile);

    // / Create the result matrix
    int result_cols = img.cols() - templ.cols() + 1;
    int result_rows = img.rows() - templ.rows() + 1;
    Mat result = new Mat(result_rows, result_cols, CvType.CV_32FC1);

//  Bitmap inFileBitmap = BitmapFactory.decodeFile(inFile);
//  Bitmap templBitmap = BitmapFactory.decodeFile(templateFile);
    // / Do the Matching and Normalize
    //Utils.bitmapToMat(inFileBitmap, img);
    //Utils.bitmapToMat(templBitmap, templ);
    Imgproc.matchTemplate(img, templ, result, match_method);
    Core.normalize(result, result, 0, 1, Core.NORM_MINMAX, -1, new Mat());

    // / Localizing the best match with minMaxLoc

    MinMaxLocResult mmr = Core.minMaxLoc(result);

    Point matchLoc;
    double minVal; double maxVal;
    if (match_method == Imgproc.TM_SQDIFF
            || match_method == Imgproc.TM_SQDIFF_NORMED) {
        matchLoc = mmr.minLoc;
    } else {
        matchLoc = mmr.maxLoc;
    }



    // / Show me what you got
    Imgproc.rectangle(img, matchLoc, new Point(matchLoc.x + templ.cols(),matchLoc.y + templ.rows()), new Scalar(0, 0,0));

    // Save the visualized detection.
    Log.i(TAG, "Writing: " + outFile);

    Imgcodecs.imwrite(outFile, img);
    return img;

}
}
2016-04-03 07:22:36 -0600 asked a question opencv +android template matching error

I am a beginner in opencv and android and i should do an application that find a template in a big image .I refered to some sites and i tried this project but i got a lot of errors:

image description

This is tha code

'public class MainActivity extends Activity implements OnClickListener{

String TAG = "Main";

private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
@Override
public void onManagerConnected(int status)
{
    switch (status) {
        case LoaderCallbackInterface.SUCCESS:
        {
            Log.i(TAG, "OpenCV loaded successfully");
        } break;
        default:
        {
            super.onManagerConnected(status);
        } break;
    }
}
};

  @Override
   public void onResume()
    {
  super.onResume();
   OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_1_0, this, mLoaderCallback);
 }

@Override
protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

Log.i(TAG, "called onCreate");
        setContentView(R.layout.activity_main);

        //Buttons
        Button btnRunIt = (Button) findViewById(R.id.btnRunIt);
        btnRunIt.setOnClickListener(this);
}

@Override
public void onClick(View v) {
        // TODO Auto-generated method stub

        @SuppressWarnings("unused")
        Intent myIntent;
        int id = v.getId();

        switch (id)
        {
                case R.id.btnRunIt :

                        TemplateMatching matchIt = new TemplateMatching();

                        Uri inFile = Uri.parse("android.resource://com.example.match/drawable/img1.png");
                        Uri templateFile = Uri.parse("android.resource://com.example.match/drawable/template.png");
                        Uri outFile = Uri.parse("android.resource://com.example.match/drawable/img2.png");

                        String[] args = new String[3];
                        args[0] = inFile.toString();
                        args[1] = templateFile.toString();
                        args[2] = outFile.toString();

                        Bitmap image = matchIt.main(args);

                        ImageView imageView = (ImageView) findViewById(R.id.imageView1);

                        imageView.setImageBitmap(image);

                        break;
                default:
                        //Unrecognized button? We should never get here
        }
}

}'

public class MatchingDemo {

  public Mat run(String inFile, String templateFile, String outFile, int match_method) {

  System.out.println("\nRunning Template Matching");

  Mat img = Imgcodecs.imread(inFile);

   Mat templ =Imgcodecs.imread(templateFile);

   // / Create the result matrix

   int result_cols = img.cols() - templ.cols() + 1;

    int result_rows = img.rows() - templ.rows() + 1;

     Mat result = new Mat(result_rows, result_cols, CvType.CV_32FC1);

     // / Do the Matching and Normalize

     Imgproc.matchTemplate(img, templ, result, match_method);

      Core.normalize(result, result, 0, 1, Core.NORM_MINMAX, -1, new Mat());

    // / Localizing the best match with minMaxLoc

     MinMaxLocResult mmr = Core.minMaxLoc(result);

      Point matchLoc;

        if (match_method == Imgproc.TM_SQDIFF || match_method == Imgproc.TM_SQDIFF_NORMED) {

      matchLoc = mmr.minLoc;
    } else {
        matchLoc = mmr.maxLoc;
   }
   // / Show me what you got
   Imgproc.rectangle(img, matchLoc, new Point(matchLoc.x + templ.cols(),
   matchLoc.y + templ.rows()), new Scalar(0, 255, 0));

   // Save the visualized detection.
  System.out.println("Writing "+ outFile);
  Imgcodecs.imwrite(outFile, img);



    return img;

}

         public class TemplateMatching {

    public Bitmap main(String[] args) {

        String infile = args[0].toString();
        String templatefile  = args[1].toString();
        String outfile = args[2].toString();

         Mat image = new MatchingDemo().run(infile, templatefile, outfile, Imgproc.TM_CCOEFF);

         Bitmap bitmap = Bitmap.createBitmap(image.cols(), image.rows(), Bitmap.Config.ARGB_8888);
         Utils.matToBitmap(image, bitmap);

         return bitmap;
    }
   }
2016-03-28 01:29:13 -0600 asked a question Can someone help me and give an android example that use opencv machine learning with java code

I am a beginner in opencv and android and i have a project that aims to detect text in a picture and then recognize this text (i should store letters(forms of pictures) in an sqlite database and then compare the letters found in the picture with those in the database and the app know each letters by reference to database .I can't use ocr system because the letters in the picture aren't clear (I tried ocr and the result was bad ,the app give me false result) so i search and i find that i can use opencv machine learning but i don't know how i do this .Please help me