Page 24 of 60

Re: PureBasic Interface to OpenCV

Posted: Thu Sep 11, 2014 10:43 pm
by JHPJHP
Hi AAT, applePi,

I've updated the examples: [ cv_analog_clock.pb ] and [ cv_cam_zone_tracking.pb ] to includes sounds.

cv_analog_clock.pb: Added a tick sound for the seconds hand.

cv_cam_zone_tracking.pb: Added a threaded component, and opted to use an API (sndPlaySound) instead of the built-in PlaySound function. I've also assigned the alarm its own switch, modifying other aspects of the code as well.

A new subfolder has been added to the binaries folder which currently includes 2 default sound files
- \binaries\sounds
-- alarm.wav
-- tick.wav

NB*: For anyone else following this thread I want to mention that the original idea for a zone alarm example was from AAT, and to include a sound file (for ghost tracking) was from applePi.

--------------------------------------------------------

Fixed a small issue in the following examples: [ cv_cam_zone_tracking.pb ] and [ cv_mov_runningavg_1.pb ].
- the webcam stopped processing images when a contour wasn't detected

Re: PureBasic Interface to OpenCV

Posted: Fri Sep 12, 2014 8:43 am
by applePi
Hi JHPJHP
thank you very much for the update, regarding the cv_cam_zone_tracking.pb somehow my webcam works much better with the new update. it works very great with the sound running in a thread, the threads idea which i never used before.
but it does not work unless i change line 222:
If alarm : *sound\PlayFile = #True : EndIf
to
*sound\PlayFile = #True

any way it works greatly even in this way, i have used tick.wav also it seems correct when i wave a pencil in front the cam, it seems to me more precise and sensible.
i will try it with a pendulum later.
i have some notes:
if i activate zone 1 by pressing 1 , then activate trace by pressing 'T' now i make the pencil approach the cam scene slowly as in the picture, it begins giving the alarm. is it possible to give the alarm only when the pencil enter zone 1 area ? and not any part of the scene.
Image

thats unexpected usages of this interface. is more usable than all the fancy expensive sensors in the market. i hope the schools, universities, the Amateurs know about it.
best wishes

Re: PureBasic Interface to OpenCV

Posted: Fri Sep 12, 2014 8:54 am
by JHPJHP
Hi applePi,

I'm glad you like the changes.

I think the reason the alarm didn't activate for you was because you didn't notice/enable the new parameter:
- see Tooltip: - [ A ] KEY: Toggle alarm.
... if i activate zone 1 by pressing 1 ... is it possible to give the alarm only when the pencil enter zone 1 area ? and not any part of the scene.
- pressing 1 to 9: [ RED ] zone is disabled, [ GREEN ] zone is enabled
- disabling zones 2 to 8 [ RED ] should give you the desired results; leave zone 1 enabled [ GREEN ]
- tracking [ T ] provides information only, showing why a zone is being activated
- with tracking ON a bounding rectangle will show as soon as it crosses into an enabled zone

Re: PureBasic Interface to OpenCV

Posted: Fri Sep 12, 2014 10:11 am
by applePi
you are right JHPJHP, i haven't noticed the 'A' key. i have disabled all the zones except zone 5 and it is now more precise. i will try to divide the scene to a more smaller zones.
thank you

Re: PureBasic Interface to OpenCV

Posted: Fri Sep 12, 2014 1:58 pm
by JHPJHP
Hi applePi,

I've updated the package once again.
... i will try to divide the scene to a more smaller zones.
There is a new example: cv_cam_zone_tracking_1.pb. I'll keep the original example: cv_cam_zone_tracking_2.pb until I hear some feedback - just incase.

The 3rd line of code has 2 Global variables that can be modified:
- nRows: min = 1, max = 10
- nColumns: min = 1, max = 10
- currently set for 3x3 (9 zones), but any configuration within 10x10 (100 zones) is allowed

Code: Select all

Global lpPrevWndFunc, nRows = 3, nColumns = 3
- on my laptop any number greater then 5x5, frame capturing is slow
- if you want to set more then 100 zones modify lines 113 & 114

Code: Select all

If nRows <= 0 : nRows = 1 : EndIf : If nColumns <= 0 : nColumns = 1 : EndIf
If nRows > 10 : nRows = 10 : EndIf : If nColumns > 10 : nColumns = 10 : EndIf
I've removed the keyboard numbers [ 1 - 9 ] for enabling / disabling zones for obvious reasons.

Use the mouse to enable or disable zones. Click the zone to change the status, with the left button held down drag the pointer over other zones to toggle their status.

The [ Z ] KEY has been added to globally toggle all zones ON / OFF.

Re: PureBasic Interface to OpenCV

Posted: Fri Sep 12, 2014 4:35 pm
by applePi
Hi JHPJHP
thank you for the new version. regarding the cv_cam_zone_tracking_1.pb this is a wise plan to use the mouse to disable/enable a zone, also using the Z key to toggle all zones on/off. this new version of course are better than the previous one since we have the choice to pinpoint more on a narrow scene area. i have tried the 10x10 and 9x9 zones and it seems it is more than enough and run okay on my desktop machine (cpu i5-2500 3.3GHZ, ram 3.24GB usable, windows 7/32, Geforce GT 520, webCam ordinary usb2 webCam sn9c201)
a funny part while running in 5x5 zones in alarm mode, i switched off the light and then the program begins the alarm, then i switched on the light and the alarm stopped immediately , and this is a good light and dark detection better than the complex electronic circuits available on the web. i will do more experiments .

Re: PureBasic Interface to OpenCV

Posted: Sat Sep 13, 2014 5:21 am
by JHPJHP
Hi applePi,

Thank you for the feedback. I deleted the old version of the example and added some additional improvements to the new version.
- [ + / - ] KEYS: Add/Remove rows & columns, hold SHIFT for columns

NOTE:
The tick.wav file is for the example: cv_analog_clock.pb. I'm using a longer playing wave file: alarm.wav because if a "ghost" quickly passes through a zone I don't want the alarm to end immediately, but to give a pronounced warning.

------------------------------------------------------------------

Updated the following examples: [ cv_distortion_1.pb ] and [ cv_distortion_2.pb ].

The examples now support outlining an area, compared with the previous select option; the results are pretty good.
- outline an area slightly larger then the one you want distorted; it may take a short while before getting the hang of it
- refer to the popup tooltips for the available options (as with any example)

Re: PureBasic Interface to OpenCV

Posted: Sat Sep 13, 2014 8:07 am
by applePi
Hi JHPJHP
regarding the cv_cam_zone_tracking.pb, this is another wise plan you have chosen to increase/decrease the number of rows and columns. i have tested it but the '+' increases only the number of columns with or without shift, while the rows are still 3. also the '-' are working only with rows with or without shift. other functions works okay.
while sleeping i have awaken for an hour and remembered my sentence above:
"the alarm stopped immediately" and "this is a good light and dark detection", i said no it will not detect a tortoise trying to open the door in 1 cm/minute speed, or the light changing very slowly like in the dawn/dusk or the heavy weight falling in the old big classic clocks, or the slow moving sailing stones http://en.wikipedia.org/wiki/Sailing_stones
so i have an idea of another example its name can be like cv_cam_zone_delayed_tracking, and its function is comparing the current scene with the scene which was 5 minutes ago as an example, this allows to detect very slow motion and the alarm here can be 2 times only. and if we choose a time number like 1000 then the program will compare the current scene with the scene which was at the absolute beginning when we initiate the alarm by pressing 'A' and the alarm here can be continuous.

the analog clock is beautiful and its ticks reminds of the old clocks, it can also have an alarm mode like the old clocks.
if i am not doing any programming at all, and have an electronics hobby, and know about cv_cam_zone_tracking functions (not easy to know, it needs an article in a popular magazine), then i should buy purebasic to run this example only, since it is cheaper than the very expensive devices.
i have talked too much sorry for that.
regards

PureBasic Interface to OpenCV

Posted: Sat Sep 13, 2014 8:42 am
by JHPJHP
Hi applePi,

I have a feeling you're using the [ + / - ] keys from the keypad (Pg Up / Pg Dn on my laptop).
- the example is using keys from the keyboards top-number-row to the right of the '0'

Another good idea, definitely something to think about:
so i have an idea of another example its name can be like cv_cam_zone_delayed_tracking
http://en.wikipedia.org/wiki/Sailing_stones: I watched a documentary awhile ago that explained what causes this... very cool.

------------------------------------------------------------

I've changed the following controls in the listed examples: KEYS: [ + / - ] to KEYS: [ < / > ].
- cv_cam_zone_tracking.pb, cv_chessboard.pb, cv_doodle.pb, cv_inpaint.pb

This should help to avoid any further confusion... Thank you for your support applePi.

------------------------------------------------------------

Applied a small fix to the following examples: [ cv_distortion_1.pb ] and [ cv_distortion_2.pb ].

Re: PureBasic Interface to OpenCV

Posted: Sun Sep 14, 2014 8:21 pm
by JHPJHP
Updated:
- added 2 examples
-- cv_cam_detect_hand.pb: contour extraction and calculation is used to determine finger, palm, and depth locations, displayed on the webcam interface
-- cv_detect_hand.pb: contour extraction and calculation is used to determine finger locations
- added 4 files to the subfolder binaries\default
-- cv_cam_default.pb: OpenCV webcam template
-- cv_default_1.pb: OpenCV image template
-- cv_default_2.pb: OpenCV drawing template
-- pb_cam_default.pb: PureBasic webcam template

cv_cam_detect_hand.pb & cv_detect_hand.pb: Based on script found here.
- produces similar results to the examples: cv_cam_convexitydefects.pb & cv_convexitydefects.pb, but achieved using "deconstructed" algorithms compared with OpenCV functions

I've updated the examples: cv_cam_convexitydefects.pb & cv_convexitydefects.pb, adding additional functionalality.

The 4 files added to the subfolder [ binaries\default ] are template files for anyone who would like to create their own examples, using the standard format I've maintained throughout "PureBasic Interface to OpenCV".

------------------------------------------------------------

The above update has been rereleased to include a new example.

Re: PureBasic Interface to OpenCV

Posted: Mon Sep 15, 2014 8:55 pm
by applePi
thanks JHPJHP for the cv_cam_detect_hand.pb example, it is amazing the contours follow my hand and the circles on the tips of my fingers. it comes to my mind immediately the fingerprints. i always fascinated by fingerprints. if there is something regarding opencv with fingerprints will be great addition.

Re: PureBasic Interface to OpenCV

Posted: Tue Sep 16, 2014 5:21 am
by JHPJHP
Hi applePi,

Thank you as always for the feedback. I think a fingerprint example is a good idea, and the initial capture should be relatively easy to implement; definitely something to think about.

If anyone is going to work with the example: cv_cam_detect_hand.pb, be sure to check out the others examples that relate to hand and finger detection:
- cv_cam_convexitydefects.pb, cv_convexitydefects.pb, and cv_detect_hand.pb

NB*: Applied a few general fixes to a couple examples, but nothing worth going into detail about.

Re: PureBasic Interface to OpenCV

Posted: Tue Sep 16, 2014 1:54 pm
by applePi
Hi JHPJHP
i am still struggling to make a good pendulum. since my current nut with a string are not good. only in one case from many i got 9.6 meters/second value using the bad pendulum. but this is a luck .i remember that the old mouse have a metal ball in it, so i will paste a string to that ball to make a pendulum. i will post a full report when making a good pendulum and good measurements.
for the purpose of measuring the gravity acceleration using the formula:
T = 2pi*SQRT(L/g)
g = 4*Pi^2*L/T^2
from http://www.kbcc.cuny.edu/academicdepart ... /exp_2.pdf

i have noticed that the purebasic_compilation are still in memory after closing the program , if we make many ticks. i have found about 15 .exe;s are floating in memory without closing. this is in win7/32 using the cv_cam_zone_tracking.pb
regards

Re: PureBasic Interface to OpenCV

Posted: Tue Sep 16, 2014 8:24 pm
by JHPJHP
Hi applePi,

Your tests with a pendulum sound very interesting, anytime math is involved my attention is peaked; see this post by DK_PETER: http://www.purebasic.fr/english/viewtop ... 12&t=56341 you may find it useful in some of your other projects.

cv_cam_zone_tracking.pb: I believe the issue with "purebasic_compilation.exe" remaining in memory after closing has been fixed. Please download the latest package, testing the updated example, confirming that the problem has been resolved.

Thank you,

Re: PureBasic Interface to OpenCV

Posted: Wed Sep 17, 2014 10:17 am
by applePi
Hi JHPJHP
thanks for the update, regarding the cv_cam_zone_tracking.pb it seems the exe in memory are solved, 2 times only when i close the program (can't remember when press esc or click 'x') the windows ask me to close the program or connect online. but in subsequent work it does not do that again. i will keep an eye on this.
i have used this ball from an old clock (used as a clock leg) not perfect swinging, it is better to use a ball which are drilled in factory across its radius so to pass the string inside it
Image
and then pasted a small card board on the ceiling with a string hanging from it,
Image
the whole pendulum is 1.96 meter approx. (the height of the ceiling are approx 3 meter)
i have used this code in replace of the :
If alarm : *sound\PlayFile = #True : EndIf

Code: Select all

If alarm And n <=10
             n + 1
             time.f = ElapsedMilliseconds()
              PrintN (StrD(time))
              *sound\PlayFile = #True
             
EndIf
there is opencosole() at the begining of the file, and closeconsole() below the line "Until keyPressed = 27 Or exitCV" near the file end
in one test i got these results, each number in milliseconds accompanied with a tick.wav sound. each subsequent 2 numbers are half period, ie (tick tack)
5287404
5288809 1405 msec for half period = 1.405 seconds
5290212
5291619 1407
5293021
5294425 1404
5295830
5297235 1405
5298639
5300042 wrong number

in another test i got these:
7338512
7339916 1404
7341322
7344145 2823
7345548
7346954 1406
7348262
7349761 1499
7352569
7353973 1404

so it seems the half period is about 1.4 sec, and the full period is 1.4 * 2 = 2.8 sec
knowing that the pendulum lengh = 1.96 meter
using the formula
g = 4*Pi^2*L/T^2 from:
http://www.kbcc.cuny.edu/academicdepart ... /exp_2.pdf
g = 4*Pi^2*1.96/(2.8^2)
g= 9.86 m/s^2 and this is almost like the 9.806
i am worrying there is something not good in the logic since sometimes i got bad results, could it be the ElapsedMilliseconds() , not sure.
the problem is that we must choose the smallest active square, and so there is a chance the camera or the program will not record the pendulum passing in front of it. i have focused the camera on the ball. since focusing it on the string sometimes will not record it (depends on its color). in principle i think using a powerful computer and a good webcam will do good results.