B4A Library OpenCV 3.x

Oke

Member
Licensed User
Longtime User
Greetings jordyCp, how to get face data to be stored in a database and match it in the future, like in an attendance machine ?
 

JordiCP

Expert
Licensed User
Longtime User
Greetings jordyCp, how to get face data to be stored in a database and match it in the future, like in an attendance machine ?
Hi Oke,

Face Detection is just the first step for Face Recognition. The second is a bit more complicated.

Opencv 3.20 for Android (from where the B4A lib was made) includes the OpenCV 3.20 'standard' modules. It can perform face detection but not recognition, since it would need one of the 'contrib' modules (specially, the module needed for face recognition is 'face', which includes EigenFaces, FisherFaces and LBPH). May be added in the future.

As an alternative approach, once you have the set of training images (you'll need a few of them), you could perhaps try Tensorflow deep learning (see THIS wrapper lib by @moster67 ). Not an expert here, but made some tests when it was published and it's really great!
 

Oke

Member
Licensed User
Longtime User
Mr. jordiCp, how to combine OpenCV320 with TensorFlowLite, thank you.
 

zmrcic

Member
Licensed User
Hi there....working on some number detection app. I will report progress here as I go. It's working fine in Python...but when I try to write same code in B4A I have some problems, numpy first...
Can someone inspect my code?
B4A
Dim alpha As Float : alpha= 2.5
Dim threshold As Int : threshold = 37
Dim adjustment As Int : adjustment= 5
Dim iterations As Int : iterations= 1
Dim blur As Int : blur= 9
Dim mCore As OCVCore
Dim mScalarTmp As OCVScalar
mScalarTmp.Set(Array As Double(alpha,alpha))


Dim img As OCVMat:img = ROI

mCore.multiply5(img, mScalarTmp,img)
mImgProc.cvtColor(img, img, mImgProc.COLOR_BayerBG2GRAY,1)
Dim SPECTRUM_SIZE As OCVSize
SPECTRUM_SIZE.Set(Array As Double(blur,blur))

mImgProc.GaussianBlur(img, img, SPECTRUM_SIZE ,blur,blur, 0)
mImgProc.threshold ( img, img,threshold,mImgProc.ADAPTIVE_THRESH_GAUSSIAN_C, mImgProc.THRESH_BINARY)

Dim kernel_SIZE As OCVSize
kernel_SIZE.Set(Array As Double(1,1))

Dim kernel As OCVMat
kernel=mImgProc.getStructuringElement1(mImgProc.MORPH_RECT, kernel_SIZE)
mImgProc.erode1(img,img, kernel,Null, iterations)

Python
alpha = float(2.5)
threshold = 37
adjustment = 5
iterations = 1
blur = 9

img = cv2.imread('Moje.jpg')
exposure_img = cv2.multiply( img, numpy.array( [alpha])) #problem one....B4A and numpy
gray = cv2.cvtColor(exposure_img, cv2.COLOR_BGR2GRAY)
blurred = cv2.GaussianBlur(gray, (blur, blur), 0)
thresh = cv2.adaptiveThreshold(blurred,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY,threshold,adjustment) #problem two....no adjustment in B4A OpenCV

kernel = cv2.getStructuringElemen( cv2.MORPH_RECT, (1, 1))
eroded = cv2.erode (thresh, kernel, iterations)

#edged = cv2.Canny(gray, 30, 100)
inverse = (255 - eroded) #inverse image? bitwise_not or something else?

thanks....
 

JordiCP

Expert
Licensed User
Longtime User
A new version based on OpenCV 3.4.1 (so the thread title will be changed from OpenCV320... to OpenCV 3.X) is ready and will be released during today, after some tests.

Besides some minor bug fixes in the previous wrapper, one of the main additions is the DNN module, which allows for image classification using trained networks from other frameworks.

Here is the result of this OpenCV example ported to B4A

 

syerif

Active Member
Licensed User
Longtime User
hi, i try your code for face detector and return error not found file, xml and png where i can download it

Thanks
 

rbghongade

Active Member
Licensed User
Longtime User
Hi JordiCP,
Great work. Tried to compile the example. But am getting this compile error.

Thanks for the great library.
 

syerif

Active Member
Licensed User
Longtime User
I removed them by mistake. Just updated the project in the first post with the correct files.

i got new error can not load cascade file, i have attach your cascade file in asset, any sugestion to run your code

Thanks
 

JordiCP

Expert
Licensed User
Longtime User
i got new error can not load cascade file, i have attach your cascade file in asset, any sugestion to run your code
Now solved (Facedetector8 in the first post)
The original one was a bit old and made use of a low targetSDK (14) --> raised it to 28 and made 2 small changes
  • Cascade files need to be copied to internal storage first (OpenCV can't load it directly from assets). The original example made use of File.DirRootExternal. Now changed to File.DirInternal
  • Added runtimepermission for camera
 

rbghongade

Active Member
Licensed User
Longtime User
Thanks Erel and JordiCP, able to run it with real device.
One (silly) question: Can we use the same library with B4J?
 

JordiCP

Expert
Licensed User
Longtime User
This version is only for Android, some of the internal libs needed (specially the camera) are Android-specific.
A B4J version will come but can't say when
 

wang xue feng

New Member
Licensed User
This version is only for Android, some of the internal libs needed (specially the camera) are Android-specific.
A B4J version will come but can't say when
I want to complete the function of green screen button image, can it be realized? colorkey? thank you!
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…