Liberty BASIC Community Forum
« Video input »

Welcome Guest. Please Login or Register.
Jul 25th, 2017, 11:39am


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Video input  (Read 430 times)
Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5366
xx Video input
« Thread started on: Feb 10th, 2016, 1:32pm »

I have never had any success with video input. Has anyone? What is your secret? What do we need to do to grab video bmps or short animations from video streams like a web cam or avi/mp4?
User IP Logged

michael
Team Liberty BASIC


member is offline

Avatar




PM


Posts: 111
xx Re: Video input
« Reply #1 on: Feb 10th, 2016, 6:37pm »

As with anything on the net I ask readers to proceed with caution with this link.

Here is something that may help on the API area:

http://stackoverflow.com/questions/5069104/fastest-method-of-screen-capturing
I don't know the trust level of this link.. But since you have knowledge beyond mine of APIs, you would find a solution without risking their download links on the next page.
User IP Logged

I like making program generators and reinventing the wheel.. I never make mistakes.. Not ever.. (lie)
Dan Teel
Guru
ImageImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 1130
xx Re: Video input
« Reply #2 on: Feb 10th, 2016, 9:52pm »

The link you provided talks more about capturing screen data, instead of connecting to a device or capturing data streaming from an mp4.

But along those lines, I wonder if you could open a program that does stream video from a device and use screen capturing to get the image. Its not an elegant solution, and I would push for trying to connect to a device instead of this. I know in the past I've not had success with using the GDI to capture video off of windows media player, so that would be a hurdle.
User IP Logged

ZPtr.net
mmiscool
Team Liberty BASIC


member is offline

Avatar



AIM
Homepage PM

Gender: Male
Posts: 225
xx Re: Video input
« Reply #3 on: Feb 12th, 2016, 10:51pm »

There was a web cam video capture program that I used years agoe for making a rudimentary image recognition program. I think that if you search for image recognition on the just basic forums you might find a link to it.

Will have to look and see if I can dig up the code.this would be from around 2005 or 2006.
User IP Logged

http://mmiscool.com
http://esp8266basic.com
http://smbisoft.com
Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5366
xx Re: Video input
« Reply #4 on: Feb 14th, 2016, 09:34am »

This is the link to Callum's Video Capture example

I have tried over many years to get this to work for me. I have had three or more PC's and I was never able to get the code to work. It always failed to connect to my camera. My camera worked with other software but would never return true when the WM_CAP_DRIVER_CONNECT (1034)message was sent.

I tried again recently, just once or twice I got a brief glimpse of something flashing on screen but then back to black and no connection. So I browsed, a lot of folks had the same problem with the message. Some said code a delay, no luck with that, so I tried just sending a stream of connect messages That worked! for the first time I can now connect reliably to my webcam.

Now this is an ugly fix, there has to be something going on and we might yet get a guru to code a more elegant fix.

This is how I changed the code.


Code:
    'Connect to the device the user specified
   while test=0 and count <100
    calldll #user32, "SendMessageA", _
        hWndC as ulong, _
        1034 as ulong, _
        DevNum as long, _
        0 as long, _
         test as long
      count=count+1
      wend

    'If test is 0 then something went wrong
    if test = 0 then
        notice "Cannot connect capture device"
        goto [quit.main]
    end if

[main.inputLoop]   'wait here for input event
    wait

 


The same type of fix made Dan's more recent code in the LBGfx thread work also.
« Last Edit: Feb 14th, 2016, 09:37am by Rod » User IP Logged

Joseph
Board Moderator

member is offline

Avatar

Hello, World!


PM

Gender: Male
Posts: 854
xx Re: Video input
« Reply #5 on: Feb 15th, 2016, 9:36pm »

Hi Rod, I just pulled my webcam out and tested Callum's code, and it worked for me. It must be that particular kind of webcam you have. Perhaps try a different one?
User IP Logged

My Personal LB Project Page
Twitter GitHub
My App
Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5366
xx Re: Video input
« Reply #6 on: Feb 16th, 2016, 01:30am »

Three pc's at least all with their own built in cameras?
User IP Logged

johnb
New Member
Image


member is offline

Avatar




PM


Posts: 21
xx Re: Video input
« Reply #7 on: Feb 20th, 2016, 07:07am »

this is the testcode that i use for testing web cameras. tested ms lifecam VX6000 and logitech quickcam stx. OS tested on XP,Win7 and Win10


Code:

[setup.main.Window]
  struct CAPDRIVERCAPS, _
        wDeviceIndex as ulong, _
        fHasOverlay as boolean, _
        fHasDlgVideoSource as boolean, _
        fHasDlgVideoFormat as boolean, _
        fHasDlgVideoDisplay as boolean, _
        fCaptureInitialized as boolean, _
        fDriverSuppliesPalettes as boolean, _
        hVideoIn as ulong, _
        hVideoOut as ulong, _
        hVideoExtIn as ulong, _
        hVideoExtOut as ulong

WMCAPSTART = 1024
WMCAPDRIVERCONNECT = 1034
WMCAPDRIVERGETCAPS = 1038
WMCAPFILESAVEDIB = 1049
WMCAPDLGVIDEOFORMAT = 1065
WMCAPDLGVIDEOSOURCE = 1066
WMCAPSETPREVIEW = 1074
WMCAPSETOVERLAY = 1075
WMCAPSETPREVIEWRATE = 1076
WMCAPGRABFRAMENOSTOP = 1085


    '-----Begin code for #main

    nomainwin
    WindowWidth = 805
    WindowHeight = 600
    UpperLeftX=int((DisplayWidth-WindowWidth)/2)
    UpperLeftY=int((DisplayHeight-WindowHeight)/2)


    '-----Begin GUI objects code

    graphicbox #main.ref, 360, 280, 320, 240
    graphicbox #main.scr,  15, 280, 320, 240
    graphicbox #main.gb1,  10,   10, 320, 240
    statictext #main.statictext4, "Source",  15, 260,  43,  20
    statictext #main.statictext5, "Reference", 360, 260,  63,  20
     statictext #main,"Binary",340,70,50,20
    textbox #main.bin0,400,70,50,20
    textbox #main.bin1,460,70,50,20
    textbox #main.bin2,520,70,50,20


    button #main.scr,"Source",[source], UL, 350,  10,  53,  25
    button #main.ref,"Reference",[reference], UL, 410,  10,  73,  25
    button #main.comp,"Compare",[comp], UL, 490,  10,  66,  25
    button #main.clr,"Clear",[clear],ul,565,10,53,25
   button #main.ext,"Exit",[quit.main], UL, 625,  10,  40,  25
    menu #main,"File","Exit",[quit.main]
     menu #main,"Camera","Size",[CamFormat],"Preference",[CamSource],"Camera On",[CamOn],"Camera Off",[CamOff]
    global FileName$,ScrIm$,RefIm$
    '-----End GUI objects code

    open "Cam Test" for window as #main
    print #main.gb1, "down; fill white; flush"
    print #main.scr, "down; fill white; flush"
    print #main.ref, "down; fill white; flush"
    print #main, "font ms_sans_serif 10"
    print #main, "trapclose [quit.main]"

  open "AVICAP32.dll" for DLL as #vfw
  hw1 = hwnd( #main)
    calldll #user32,"GetDC", hw1 as ulong, hdc as ulong

    'Get the Windows handle
    hWnd = hwnd(#main)
 ' wait
    'Set the style for the capture window
    dwStyle = _WS_VISIBLE OR _WS_CHILD

    'Set the capture window name
    lpszWindowName$ = "Capture Window"

    'And finnaly, create the capture window
    calldll #vfw, "capCreateCaptureWindowW", _
        lpszWindowName$ as ptr, _
        dwStyle as ulong, _
        10 as long, _
        10 as long, _
        320 as long, _
        240 as long, _
        hWnd as ulong, _
        100 as long, _
         hWndC as ulong
DevNum=0
      #main.gb1, "down; fill black; flush"
         txt$="Connecting .........."
       #main.gb1 "backcolor black;place 0 0"
       #main.gb1 "color white"
      #main.gb1 "font ms_sans_serif 12;place 30 70;\";txt$;" "
      #main.gb1 "flush"
    'Connect to the device the user specified

    calldll #user32, "SendMessageA", _
        hWndC as ulong, _
        WMCAPDRIVERCONNECT as ulong, _
        DevNum as long, _
        0 as long, _
         test as long

    'If test is 0 then something went wrong
    if test = 0 then
        notice "Cannot connect capture device"
        goto [quit.main]
    end if

    '*************Notice **************************
'change value to save bmp to your chosen loction
ScrIm$="C:\temp\source.bmp"
RefIm$="C:\temp\refer.bmp"
'Turn Camera On
   gosub [PreOn]


[main]   'wait here for input event
scan
CallDll #kernel32, "SleepEx", 5 As long, True As ulong, ret As ulong
    wait

[CamOn]
gosub [PreOn]
goto [main]

[CamOff]
gosub [PreOff]
goto [main]

[source]   'Perform action for the button named 'scr'
        FileName$=ScrIm$
        gosub [CapStill]
        loadbmp "scr",ScrIm$
        #main.scr, "down ; drawbmp scr 0 0 ; flush"
        #main.scr, "segment dSeg"
        #main.scr,"delsegment dSeg"
       wait


[reference]   'Perform action for the button named 'ref'
        FileName$=RefIm$
        gosub [CapStill]
        loadbmp "ref",RefIm$
        #main.ref, "down ; drawbmp ref 0 0 ; flush"
        #main.ref, "segment dSeg"
        #main.ref,"delsegment dSeg"
       wait


[comp]   'Perform action for the button named 'comp'
binval=0:tt=0:t1=0
    open ScrIm$ for binary as #11
    open RefIm$ for binary as #22
      for x= 10 to 320 step 25
      for y= 5 to 235 step 5
        seek #11,(y*320+x)*3+54
        src$=input$(#11,24)
        seek #22,(y*320+x)*3+54
        chk$=input$(#22,24)
        v=0
        for p= 1 to 22 step 3
            v=v+abs(asc(mid$(chk$,p,1))-asc(mid$(src$,p,1)))
            v=v+abs(asc(mid$(chk$,p+1,1))-asc(mid$(src$,p+1,1)))
            v=v+abs(asc(mid$(chk$,p+2,1))-asc(mid$(src$,p+2,1)))
           next
        t=t+v
        if v>=320 then ndiff=ndiff+1
        t1=t1+1
       next
     tt=tt+t
    t=0
next
binval=100*tt/t1/3/255
ndval=100*ndiff/t1/3
#main.bin0,tt
#main.bin1,using("###.##",binval)
#main.bin2,using("###.##",ndval)
close #22
close #11
wait


[clear]   'Perform action for the button named 'ext'
#main.scr,"down; fill white; flush"
#main.ref,"down; fill white; flush"
#main.bin0,""
#main.bin1,""
#main.bin2,""
    'Insert your own code here

    wait

[quit.main] 'End the program
confirm "Quit";quit$
 if quit$ = "no" then wait
 calldll #user32, "DestroyWindow",_
        hWndC as ulong, _
         ret as long
    close #vfw
    close #main
    end

 [CapStill] 'Capture a still image

    if FileName$="" then notice "No File name selected ":wait

     calldll #user32, "SendMessageA",_
        hWndC as ulong,_
        WMCAPGRABFRAMENOSTOP as ulong,_
        0 as long,_
        0 as long,_
         test as long

    'This saves that frame to the file the user specified, in BMP format
    calldll #user32, "SendMessageA",_
        hWndC as ulong,_
        WMCAPFILESAVEDIB as ulong,_
        0 as long,_
        FileName$ as ptr,_
         test as long
       return


[PreOn]   'Turn preview on

    wSize = len(CAPDRIVERCAPS.struct)

    calldll #user32, "SendMessageA", _
        hWndC as ulong, _
        WMCAPDRIVERGETCAPS as ulong, _
        wSize as long, _
        CAPDRIVERCAPS as struct, _
         test as long

if CAPDRIVERCAPS.fHasOverlay.struct = 0 then
    'This enables preview mode
    calldll #user32, "SendMessageA", _
        hWndC as ulong, _
        WMCAPSETPREVIEW as ulong, _
        -1 as long, _
        0 as long, _
         test as long

   'this sets the the frame rate
    calldll #user32, "SendMessageA", _
        hWndC as ulong, _
        WMCAPSETPREVIEWRATE as ulong, _
        66 as long, _
        0 as long, _
         test as long
else
    calldll #user32, "SendMessageA", _
        hWndC as ulong, _
        WMCAPSETOVERLAY as ulong, _
        -1 as long, _
        0 as long, _
         test as long
end if
    return

[PreOff]
 'This disables preview mode

if CAPDRIVERCAPS.fHasOverlay.struct = 0 then
     calldll #user32, "SendMessageA", _
        hWndC as ulong, _
        WMCAPSETPREVIEW as ulong, _
        0 as long, _
        0 as long, _
         test as long
else
    calldll #user32, "SendMessageA", _
        hWndC as ulong, _
        WMCAPSETOVERLAY as ulong, _
        0 as long, _
        0 as long, _
         test as long
end if

'print #m.gb1, "down; fill Black; flush"
      return

[CamSource]   'Display the source dialog box

        calldll #user32, "SendMessageA",_
            hWndC as ulong, _
            WMCAPDLGVIDEOSOURCE as ulong, _
            0 as long, _
            0 as long, _
             test as long
        goto [main]

[CamFormat]   'Display the format dialog box

        calldll #user32, "SendMessageA",_
            hWndC as ulong, _
            WMCAPDLGVIDEOFORMAT as ulong, _
            0 as long, _
            0 as long, _
             test as long
        goto [main]


 
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5366
xx Re: Video input
« Reply #8 on: Feb 20th, 2016, 1:37pm »

Not at home for a day or two but interested to see if the code will fire up my built in camera.
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5366
xx Re: Video input
« Reply #9 on: Feb 23rd, 2016, 09:34am »

Now had a chance to test. The code worked perfectly first run then failed to do it again. I wonder if it is to do with disconnecting the camera properly?

Anyways your code runs reliable with this change.

Code:
while test=0 and count<50
        calldll #user32, "SendMessageA", _
        hWndC as ulong, _
        WMCAPDRIVERCONNECT as ulong, _
        DevNum as long, _
        0 as long, _
        test as long

        count=count+1
wend
 


That is sending a stream of connect messages till you get a positive response.
User IP Logged

johnb
New Member
Image


member is offline

Avatar




PM


Posts: 21
xx Re: Video input
« Reply #10 on: Feb 23rd, 2016, 10:45am »

Rod

try adding this before it attempts to connect
Code:

WMCAPDRIVERDISCONNECT = 1035

calldll #user32, "SendMessageA", _
        hWndC as ulong, _
        WMCAPDRIVERDISCONNECT as ulong, _
        DevNum as long, _
        0 as long, _
         test as long

 





User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5366
xx Re: Video input
« Reply #11 on: Feb 23rd, 2016, 1:35pm »

Nope, still just refuses to connect, only sending repeated connect messages seems to get round the problem.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls