B4A Library OpenCV 3.x

JordiCP

Expert
Licensed User
Longtime User
Do you mean that the example is not accurated when using the cascadG file? How isn't it accurate? ---> the coordinates are not correct or it doesn't detect what you want?
 

jchal

Active Member
Licensed User
Longtime User
cascadG file
it does not detect a human when it passes infornt of the camera, it detects may other things but not a human, why?
 

JordiCP

Expert
Licensed User
Longtime User
There may be different issues: one of them is that the xml file is poorly trained. Later I'll try to find a better trained file and adapt the example to see if it works better.

Also, a bit of background is needed to understand why things don't work as expected. If you don't make the effort to investigate yourself what each function does, and what the parameters mean, I won't be able to assist you anymore.
 

jchal

Active Member
Licensed User
Longtime User
maybe it is possible to have pooly trained hml files, what i try to do is to understand how it works, there for i tryed to use difrent hml files to see if it works
if you try it your self you will see what i mean.
my phone locates something in a second but it a chair with my shirt on it and it is not a human the next secont it detects the miror and it is not a human ther miror show a window not a human.
the other hxml file is for detecting fire, well it detects difrent things every second.
in both cases what i thing the proper action must be .
for the 1st case human
no detection until camera sees a human
in the 2nd case
no detection until camera sees a fire or a smoke , i still dont know what the xml file acutualy is , is it fie or smoke.
therefore i am asking the community, that has more experiance than me how can i correct if possible this falut.
is it a poor xml? or it is something else?
also the idea of the detection is the same no matter if it is face, car, body, cat please correct me if i am wrong
 

JordiCP

Expert
Licensed User
Longtime User
ok, I'll try to give a little bit of background. Please understand that all what I will say here can be found in internet, and possibly much better explained than what I do here. That's why I can't write tutorials about it (and why the only advice I can give is to read and investigate, and never assume that things have to work in a certain way)

Background: there are different types of "detection" techniques in OpenCV, all of them based on some 'properties' (visible or mathematical) of the image or group of images.
  • There are, for instance, detectors based on color, where compact groups of pixels which are 'near' to a given color are detected and then can be classified based on size, shape, ...
  • Other detectors can be based on movement: for instance if the camera is static you can compute the difference between frames to find moving objects.
  • Then there are some more complex ones, based on cascade classifier files (which is the case for facedetector, human body, ...). They need 2 parts to make them work:
    • On one side, some files (don't ask me how they work internally) that have been trained with hundredths (preferably, thousands) of "positive" images and hundredths of negative images of a certain "thing" (and eye, a license plate, a donkey, an apple). If you have trained it for apples, and you have used only green apples, then when you try to detect a red apple it won't succeed. The same for faces: if you have only trained for frontal looking faces of people without glasses, it will probably fail to detect anything when a slightly rotated face of someone with glasses.
    • On the other side, you have the 'detector'. The detector is nothing else than an algorithm that takes the frames as an input, and, according to some parameters and the cascade classifier file, gives some outputs. These outputs basically mean that it has found enough features in the image which, compared to the file, seem to contain the object it was looking for. About the configuration parameters that can affect detector performance, they are
B4X:
  mFaceDetector.detectMultiScale(mGray,faces,1.1,2,2,mSize,mSize2)  
  '1st parameter: source Mat
  '2nd parameter: list where the detector will place the detected objects (in this case, faces)
  '3rd parameter: scaleFactor --> the set factorby which the algorithm will consecutively reduce the source mat to find features (recommended value)
  '4rt parameter: minNeighbours
  '5th parameter: flags
  '6th parameter: minSize --> minimum size of object to detect. If you know that some objects must appear in the image bigger than a certain size, this will help the detector
  '7th parameter: maxSize: --> the same for max size. Leave uninitialized if not used.
      • All this information can be found HERE, if you google for opencv + detectmultiscale


  • In short, just think that both the detector and the files are really powerful but very silly, because they will only work based on the information they have. For instance, if the "fire" file has been trained only with fire from a match, but not from a forest, perhaps its color (blueish against reddish or other) or its shape, will be so different that it will say: no, the image you are showing me is not similar enough to the ones that I have in my database, so for me it is not a 'fire'. So, the detector won't detect anything and you will think that it does not work....
 

cramarc

New Member
Licensed User
Longtime User
Hello JordiCP

As a user of B4A for some years, but newby in OpenCV
I would have interest to try you library for some robot experiments.
I hope my skill and research on the internet and of course your lib
will help me to do some recognitions in live time on a small robot.
If success I hope to combine it with IOT ( MQTT )
Please, if lib still available, let me know how to download the library.

Many thanks
CraMarc (Huyghe Marc)
 

JordiCP

Expert
Licensed User
Longtime User
Sure, please PM me with your mail address.

Are these robots running Android (or sending the acquired images to an android device)?
 

cramarc

New Member
Licensed User
Longtime User
Hello JordiCP,

Thanks for the fast response.

In fact I will try use the Android as an intelligent sensor ( intern camera ) which does some pre-processing on captured pictures.
The results should be shared in a network " Internet of things " (MQTT) where other units ( mostly ESP8862 ) will do
the other jobs. It will be a sort of multiprocessing with a very flexible and wide programming experiment.
It could also be done by a "Client - Server" network as the ESPs do have WIFI
The Android does not need to activate external hardware directly.
I have already done the first part ( driving and control with simple sensors )
but working with camera will be total new for me, and I am a little afraid to have enough knowhow on these technics(maths).

My E-Mail is huyghe_marc@telenet.be

Greets from DEINZE in BELGIUM (EU) and thanks in advance.

CraMarc ( Marc )
 

jchal

Active Member
Licensed User
Longtime User
in face detector i want to mark an area like a square or place a line and every time it passes the line or everytime it is withn the maked area to display a message on screen, how can i do it?
how can i drow the line or the square and tell it to send me a message on screen?
 

stu14t

Active Member
Licensed User
Longtime User

I think, to be fair to @JordiCP , He's done a magnificent job in porting this to B4A and now it's over to us, as programmers, to work out for ourselves what is needed to achieve our goals.

Yes, do ask him if it's specifically to do with the Lib but also learn for yourself how to do these things, it is far more rewording and you learn quicker too.
 

jchal

Active Member
Licensed User
Longtime User
dear stu14t i understand and agree that jordiCP has done a greate job in this lib but you must have in mind that different people learn in different ways,
my question to the comunity was what way i must use in order to do this. i am a learner you see not an expert!
 

moster67

Expert
Licensed User
Longtime User
Personally I think the best way is to try to translate the examples you can find on the Internet. You can probably find examples which are similar to what you want to do by googling and/or studying many of the examples available. It's true that most of them are either in C++ or Python but if you examine the code you should be able to translate the code to be used with B4A/B4A OpenCV wrapper.
 

JordiCP

Expert
Licensed User
Longtime User
I agree. The fact is that the OpenCV user base in B4A isn't yet broad enough (and perhaps will never be, since it is quite specific and not trivial) so that there could be more examples to learn from, as a "first contact" companion before jumping to internet.

Take a look to faceDetector5 example (first post in this thread). I show how to draw a rectangle on the screen (the one that bounds the detected face, if any). So this is the way to draw. In a similar way, to draw a line, you can use
B4X:
mImgProc.line(....)    '<-- mImgProc has been declared at the beginning of the example as Dim mImgProc as OCVImgProc
Note that most of the 'static' utility methods are in mImgProc ( which has type OCVImgProc) and mCore (which has type OCVCore)

You want to draw another rectangle or line on the screen and be alerted when the face crosses the line----> OpenCV will not do it for you. But you already have all the information, so it is just programming. The detected face is inside a bounding rectangle (the one that we draw in the example). You just must compare its coordinates (explore the fields of OCVRect) with the ones of the bigger rect or the line, and it the comparison gives the expected results, you can draw text on the screen with mImgProc.putText (or putText1 or putText2, depending on parameters).


I know there is not a lot of material, but I spent many hours building the examples to help, so the first thing to do is to try to understand them, since they can answer some questions.
 

barzaghino1

New Member
Licensed User
Longtime User
I'd be interested to see your work

Many thanks for creating this.

PM on the way

tell me How much the donation is? thanks
 

padvou

Active Member
Licensed User
Longtime User
Hello,
could you please help me recognize a specific shape for example a rectangle or circle in an image?
I'm new with this and I could appreciate any help.
Thank you.
 

JordiCP

Expert
Licensed User
Longtime User
Hi padvou,
You must think of OpenCV as a big 'set' of powerful functions for processing. The problem can be faced in different ways, but it will always work better if it has some 'clues' (as many as you can give it)

For instance:
Is it a preloaded image or real-time input from a camera?
in case of a circle: is it always filled with a color (and is it the same color)? Which is the (relative to picture dimensions) minimum and maximum size that it can have?
For square, nearly the same questions: also, will the square be aligned to picture edges or can it be in 'perspective'?

The 'optimum' way to program it will depend on the answers to these questions. With these answers (also, if you can send an example picture will be much better), I (or others) will try to help you.
 

padvou

Active Member
Licensed User
Longtime User

Hi Jordie,

This is something like the one I would like to detect on a loaded image in a panel.
Of course I can change it so that the mid circle is black etc.
The relative dimensions are not known beforehand unfortunately. As the camera can move back and forth the relative dims get smaller or larger. But the shape to be detected remains the same.
The goal is to detect the position of the center of the circle in the panel, so that I can take the X and Y coordinates for further use.
 

padvou

Active Member
Licensed User
Longtime User
Cookies are required to use this site. You must accept them to continue using the site. Learn more…