Skip to content

Instantly share code, notes, and snippets.

View ahmedfgad's full-sized avatar

Ahmed Gad ahmedfgad

View GitHub Profile
package com.example.dell.opencvandroid;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import org.opencv.android.OpenCVLoader;
import org.opencv.core.Mat;
package opencvapp;
import java.io.File;
import org.opencv.core.Core;
public class TrainANN {
public static void main(String [] args){
String currentDirectory = System.getProperty("user.dir");
System.load(currentDirectory + "\\OpenCVDLL\\x64\\" + Core.NATIVE_LIBRARY_NAME + ".dll");
package opencvapp;
import java.io.File;
import java.util.Arrays;
import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.MatOfFloat;
import org.opencv.core.MatOfInt;
import org.opencv.imgcodecs.Imgcodecs;
package opencvapp;
import java.io.File;
import java.util.Arrays;
import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.MatOfFloat;
import org.opencv.core.MatOfInt;
import org.opencv.core.TermCriteria;
package opencvapp;
import java.io.File;
import java.util.Arrays;
import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.MatOfFloat;
import org.opencv.core.MatOfInt;
import org.opencv.imgcodecs.Imgcodecs;
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.dell.opencvandroid.MainActivity">
<TextView
android:layout_width="match_parent"
public static String getPath(final Context context, final Uri uri) {
final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
// DocumentProvider
if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
// ExternalStorageProvider
if (isExternalStorageDocument(uri)) {
final String docId = DocumentsContract.getDocumentId(uri);
final String[] split = docId.split(":");
public void predictANN(View v){
EditText imgPath = findViewById(R.id.imgPath);
Mat imgBGR = Imgcodecs.imread(imgPath.getText().toString());
Mat imgHSV = new Mat();
Imgproc.cvtColor(imgBGR, imgHSV, Imgproc.COLOR_BGR2HSV);
// Preparing parameters of Imgproc.calcHist().
MatOfInt selectedChannels = new MatOfInt(0);
Mat imgHist = new Mat();
package com.example.dell.opencvandroid;
import android.content.ContentUris;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.provider.DocumentsContract;
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">