Posts

Edit image with Android and OpenCV and JNI (C/C++)

Image
Requires: opencv android SDK (2.4.13.2) android ndk (r14b) to build JNI eclipse + ADT plugin Note: tools version above while writing this blog. After tutorial you can: call C/C++ library in Java in your app edit image with android and opencv embed features wrote by C/C++ to Android (Java) app improve your app speed by using native (C/C++) idea to apply some secure method by using native code Source code:  https://github.com/vmtram/OpencvJni Relative video: https://youtu.be/qCCC9Y1ldUs Create android project add a image view and a button to main layout, then import opencv library. <?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:background= "@android:color/holo_green_dark"...

Install OpenCV to work with Python

Image
This tutorial will install OpenCV 2.4 for Python 2.7on Windows. Download OpenCV for your OS from  https://sourceforge.net/projects/opencvlibrary/files/ I use opencv cv 2.4 for windows  https://sourceforge.net/projects/opencvlibrary/files/opencv-win/2.4.13/ Extract opencv to a folder  Install Python 2.7 Copy file cv2.pyd in folder /opencv/build/python/2.7/x64 to Python27/Lib/site-packages/ We will need instal numpy library: pip install numpy Test with simple code: import cv2 print "Read image with opencv" img = cv2 . imread( "E:/test.png" ) print "Convert to gray" img = cv2 . cvtColor(img, cv2 . COLOR_BGR2GRAY) print "Write gray image" cv2 . imwrite( "E:/gray.png" , img) print "------ Done -------" Result:

Recognize text from image with Python + OpenCV + OCR

Image
Requires Python 2.7 Pillow (3.4.2) pytesseract (0.1.6) => OCR numpy (1.11.2) Opencv-2.4.13 (cv2)=> OpenCV Note: library version above while writing this blog. You may need  How to install OpenCV to work with Python? We use OpenCV before recognize text from image to increase accuracy. Video: https://youtu.be/83vFL6d57OI Source code: import cv2 import numpy as np import pytesseract from PIL import Image # Path of working folder on Disk src_path = "E:/Lab/Python/Project/OCR/" def get_string (img_path): # Read image with opencv img = cv2 . imread(img_path) # Convert to gray img = cv2 . cvtColor(img, cv2 . COLOR_BGR2GRAY) # Apply dilation and erosion to remove some noise kernel = np . ones(( 1 , 1 ), np . uint8) img = cv2 . dilate(img, kernel, iterations = 1 ) img = cv2 . erode(img, kernel, iterations = 1 ) # Write image after removed noise cv2 . imwrite(src_path + "removed_nois...

Easy to code Java with C/C++

Image
Easy to code Java with C/C++ Generate file header for class in Java (use to include in C/C++) Include file header in project C/C++ in Visual studio and write code => create .DLL file Call .DLL file in Java code 1.  Generate file header for class in Java (I using Netbeans) Write class in java with some "native" methods. Class MyNative with two methods Sum and Sub Open cmd and redirect to source folder ..projectname/src run: javah javaandccplus.MyNative After run it, we have a file header javaandccplus_MyNative.h with code  /* DO NOT EDIT THIS FILE - it is machine generated */ #include <jni.h> /* Header for class javaandccplus_MyNative */ #ifndef _Included_javaandccplus_MyNative #define _Included_javaandccplus_MyNative #ifdef __cplusplus extern "C" { #endif /*  * Class:     javaandccplus_MyNative  * Method:    Sum  * Signature: (II)I  */ JNIEXPORT jint JNICALL Java_ja...