URI:
   DIR Return Create A Forum - Home
       ---------------------------------------------------------
       techno game dev forum
  HTML https://technogamedevforum.createaforum.com
       ---------------------------------------------------------
       *****************************************************
   DIR Return to: BASIC board
       *****************************************************
       #Post#: 23--------------------------------------------------
       Program  to Determine distance between selected points on an Ima
       ge
       By: OlDosLover Date: March 27, 2012, 12:46 am
       ---------------------------------------------------------
       Hi all,
       Here is the start of a program to measure distances within a
       picture of different objects. One left clicks then holds the
       button down and drags until releasing the button to indicate the
       end of the drawn "line". The line is just a visual indication of
       where your first click starts and where it will end. Upon
       release of the button the screen co-ordinates are displayed. One
       can use algebra to determine the distance between the ends of
       the lines.
       [code]REM
       DEFLNG A-Z
       DIM SHARED mx%, my%, mbl%, mbr% '           mouse x and y and
       button status array
       DIM SHARED PlaceX1 AS INTEGER '             1st left horizontal
       co-ord
       DIM SHARED PlaceY1 AS INTEGER '             1st left vertical
       co-ord
       DIM SHARED PlaceX2 AS INTEGER '             2nd right horizontal
       co-ord
       DIM SHARED PlaceY2 AS INTEGER '             2nd right vertical
       co-ord
       Pink& = _RGB32(255, 105, 180) '             hot pink color to
       print with
       SCREEN _NEWIMAGE(640, 480, 32) '            create our output
       visual screen with same dimentions as picture
       Pic& = _LOADIMAGE("David.jpg", 32) '        create a surface and
       load our picture into it.
       _MOUSESHOW '                                show the mouse
       cursor
       Down% = 0: First% = 0: Last% = 0 '          variables to flag
       button down,first and second point
       'Instructions
       PRINT "Left mouse click and hold button down while dragging
       cursor to create a line"
       PRINT "On button release the left and right co-ordinates will be
       shown"
       PRINT "Then click any key to redraw a new line,etc"
       Dummy$ = INPUT$(1)
       DO
       _LIMIT 30
       _PUTIMAGE , Pic&, 0 '                     copy our original
       pic continually to screen to overwrite whats there
       OldDown% = Down% '                        update our old value
       in button monitoring variable
       GOSUB MousePoll '                         check for mouse
       changes
       IF mbl% = -1 THEN GOSUB Show1 ELSE GOSUB Show2 ' toggle left
       mice button variable
       GOSUB Compare '                           discover if we at
       1st click, continuing button hold or button release
       LINE (PlaceX1, PlaceY1)-(PlaceX2, PlaceY2), _RGB32(255, 105,
       180) ' Draw a line in pink
       _DISPLAY
       LOOP UNTIL _KEYDOWN(27)
       SLEEP
       SYSTEM
       MousePoll:
       DO WHILE _MOUSEINPUT
       mx% = _MOUSEX: my% = _MOUSEY: mbl% = _MOUSEBUTTON(1): mbr% =
       _MOUSEBUTTON(2)
       LOOP
       RETURN
       Show1:
       Down% = 1 'toggle as button down
       RETURN
       Show2:
       Down% = 0 'toggle as button up
       RETURN
       Compare:
       'first left click
       IF OldDown% = 0 THEN
       IF Down% = 1 THEN
       IF First% = 0 THEN
       First% = 1: PlaceX1 = mx%: PlaceY1 = my%
       END IF
       END IF
       END IF
       'still holding button down
       IF OldDown% = 1 THEN
       IF Down% = 1 THEN
       IF First% = 1 THEN
       Last% = 0: PlaceX2 = mx%: PlaceY2 = my%
       END IF
       END IF
       END IF
       'left button released
       IF OldDown% = 1 THEN
       IF Down% = 0 THEN
       First% = 1: PlaceX2 = mx%: PlaceY2 = my%: Last% = 1
       END IF
       END IF
       'achieved so reset variables
       IF First% = 1 AND Last% = 1 THEN
       Position1$ = STR$(PlaceX1) + "," + STR$(PlaceY1) 'compose a
       string containing the start figures
       Position2$ = STR$(PlaceX2) + "," + STR$(PlaceY2) 'compose a
       string containing the end figures
       OldDown% = 0: Down% = 0: First% = 0: Last% = 0 '  reset all
       monitoring variables
       GOSUB ShowFigures '                               print the
       co-ords and wait for keypress
       END IF
       RETURN
       ShowFigures:
       COLOR Pink&
       _PRINTMODE _KEEPBACKGROUND , 0 '           tell program to make
       text backgroung transparent
       _PRINTSTRING (PlaceX1, PlaceY1), Position1$, 0 '   print the
       string at this position
       _PRINTSTRING (PlaceX2, PlaceY2), Position2$, 0 '   print the
       string at this position
       _DISPLAY
       _DELAY 1
       SLEEP
       RETURN
       [/code]
       Here a URL to the
       image:
  HTML http://dl.dropbox.com/u/10291175/David.jpg
  HTML http://dl.dropbox.com/u/10291175/David.jpg
       OlDosLover.
       #Post#: 30--------------------------------------------------
       Re: Program  to Determine distance between selected points on an
        Image
       By: OlDosLover Date: March 28, 2012, 10:20 am
       ---------------------------------------------------------
       Hi all,
       Could someone test this program to make sure it works on
       thir computer also please. Be aware if you use Linux please edit
       the bas file to reflect the uppercase and lowercase way the
       David.jpg file name appers on your computer else it may error
       out . Windows treats all file names as uppercase! where Linux
       doesn't.
       OlDosLover.
       
       #Post#: 32--------------------------------------------------
       Re: Program  to Determine distance between selected points on an
        Image
       By: axlyon Date: April 27, 2012, 2:02 pm
       ---------------------------------------------------------
       this is in QB64 right?
       #Post#: 35--------------------------------------------------
       Re: Program  to Determine distance between selected points on an
        Image
       By: johnfree Date: April 29, 2012, 8:49 am
       ---------------------------------------------------------
       Anything that runs in QBASIC will run (better and faster) in
       QB64.
       Now I am desperate to know distances in 3-D.
       With TWO EYES (cameras) we get all the info we need - now it is
       a matter of calculation (from COMPARING the two images)
       This is truly how ouir eyes work and lets us resolve FINER that
       the resolution of one eye on its own!
       Oldos has shown me how to get any photo into QB64 and COMPARING
       views from a camera as it moves around is easy enough
       But though writing QBAS (and Fortran) progs since the very first
       computers (Ferranti Pegasus) I STILL need help to finish the
       prog abd get it working
       The result will be a true 3-d image - an x,y,z list of the
       entire 3-D scene (Like Catch pretends to do but always messes
       up)
       #Post#: 47--------------------------------------------------
       Re: Program  to Determine distance between selected points on an
        Image
       By: OlDosLover Date: April 30, 2012, 9:23 am
       ---------------------------------------------------------
       Hi all,
       Yes this is QB64. I NO longer write anything in QBasic or
       use the Qbasic IDE or interpreter. Was looking for independant
       confirmation that this program works as expected on other
       computers.
       OlDosLover.
       #Post#: 59--------------------------------------------------
       Re: Program  to Determine distance between selected points on an
        Image
       By: axlyon Date: April 30, 2012, 2:40 pm
       ---------------------------------------------------------
       just needed to know so i could move it
       #Post#: 64--------------------------------------------------
       Re: Program  to Determine distance between selected points on an
        Image
       By: johnfree Date: May 1, 2012, 1:08 am
       ---------------------------------------------------------
       The above mentioned QBAS vs QB64
       There is no interpreter for qb64.
       So by far the best way is to write, test and debug your progs on
       QBAS and AFTER THEY WORK take advantage of the superior speed
       and access to music etc offered by QB64
       #Post#: 79--------------------------------------------------
       Re: Program  to Determine distance between selected points on an
        Image
       By: OlDosLover Date: May 1, 2012, 6:54 am
       ---------------------------------------------------------
       Hi all,
       John the above program. Did you want to work more on it? I
       was thinking that once the "line" is drawn (the start and end
       pixels are recorded) we could compute the line length by
       treating the line as the diagonal line of a triangle. If the
       drawn line is vertical or horizontal then computing in pexels is
       linear or so it would seem to me?
       Any thoughts?
       OlDosLover.
       #Post#: 83--------------------------------------------------
       Re: Program  to Determine distance between selected points on an
        Image
       By: johnfree Date: May 1, 2012, 12:39 pm
       ---------------------------------------------------------
       Yes good old Pythagoras will help us!
       Distance is sqrt(widthsquared  + heightsquared)
       But be warned that pixel count may not be inches!(nor cm)
       What I really plan to do is COMPARE two pictures
       Let us call them Right Eye picture and Left Eye picture
       (I have a webcam with two eyes spaced like a human being)
       So just like our brain does, we can calculate the full 3-d image
       (x,y,z pixel list) by COMPRING the two views
       The human eye-brain actually does wondrous things that way and
       gets much BETTER RESOLUTION than can be resolved by either eye
       (retina) alone! They call it "optical disparity"
       *****************************************************