Thread: How to get USB ports connected to multiple cameras using C/C++ program?

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    12

    How to get USB ports connected to multiple cameras using C/C++ program?

    Hi all

    I want to detect 4 USB ports connected with 4 cameras, then manipulate those cameras to take pictures. Ideally, I would like to access them simultaneously. However, as I know, it seems beyond C/C++ can do (Hope I am wrong).

    please give me a clue if you know something.

    Thanks

    David

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    It's nothing to do with C++ per se, it's all about what drivers and APIs are available from your operating system / 3rd party libraries which may allow you to connect to USB ports.

    I mean, essentially, it begins with something following the general concept of
    open( "USB0", "r" );

    But exactly what open() is actually called depends on your OS/Compiler/libraries...
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Nov 2003
    Posts
    12
    Do you know any API or third-party package support this?

    Thanks for your reply.

    David

  4. #4
    Registered User
    Join Date
    Oct 2002
    Posts
    291
    http://ej.bantz.com/video/

    http://www.twain.org/

    Try searching for capCreateCaptureWindow and capDriverConnect

  5. #5
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    If on XP you can use Windows Imaging Acquisition(WIA). Here is a script to take a picture on each camera and save it to file.

    Code:
        Set oDeviceManager = CreateObject("WIA.DeviceManager")
    
        For Each oDeviceInfo In oDeviceManager.DeviceInfos
           If oDeviceInfo.Type = CameraDeviceType Then
                Set oImage = oDeviceInfo.Connect.ExecuteCommand(wiaCommandTakePicture).Transfer
                oImage.SaveFile "myfilename.jpg"
           End If
        Next
    http://msdn.microsoft.com/library/en.../startpage.asp

  6. #6
    Registered User
    Join Date
    Oct 2002
    Posts
    291
    anonytmouse : That looks very much like vb code, am I correct ?

  7. #7
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    VBScript I'd say. He said it was a script.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  8. #8
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Yes, just chuck it in a text file with .vbs extension and double click to run.
    You'll probably need the WIA automation download first.
    http://msdn.microsoft.com/library/en...pagewiaaut.asp

    It can, of course, be converted to C++.

    Try this nifty utility:
    http://support.microsoft.com/default...b;EN-US;216388

  9. #9
    Registered User
    Join Date
    Nov 2003
    Posts
    12
    That seems fantastic. I will try and see what I can get. Thank all of your reply and help.

    I will report what I get later.

    David

  10. #10
    Registered User
    Join Date
    Nov 2003
    Posts
    12
    I put this code in a HTML file, but it doesn't work. The file I created, which is from the example on "Getting Started with Samples" from Microsoft WIA page, is the following:

    Code:
    <html>
    <title>Sample HTA</title>
    <hta:application id="oHTA"/>
    <object ID="DeviceManager1" Width=0 Height=0 ClassID="CLSID:E1C5D730-7E97-4D8A-9E42-BBAE87C2059F"></object>
    <object ID="CommonDialog1" Width=0 Height=0 ClassID="CLSID:850D1D11-70F3-4BE5-9A11-77AA6B2BB201"></object>
    <script language="vbscript" src="wiaaut.vbs"></script>
    <script language="vbscript">
    
        Set oDeviceManager = CreateObject("WIA.DeviceManager")
    
        For Each oDeviceInfo In oDeviceManager.DeviceInfos
           If oDeviceInfo.Type = CameraDeviceType Then
                Set oImage = oDeviceInfo.Connect.ExecuteCommand(wiaCommandTakePicture).Transfer
                oImage.SaveFile "myfilename.jpg"
           End If
        Next
    
    
    </script>
    </head>
    <body scroll="no">
    </body>
    </html>
    Could you please read it and see what the wrong is?

    Thanks

    David

    Originally posted by anonytmouse
    If on XP you can use Windows Imaging Acquisition(WIA). Here is a script to take a picture on each camera and save it to file.

    Code:
        Set oDeviceManager = CreateObject("WIA.DeviceManager")
    
        For Each oDeviceInfo In oDeviceManager.DeviceInfos
           If oDeviceInfo.Type = CameraDeviceType Then
                Set oImage = oDeviceInfo.Connect.ExecuteCommand(wiaCommandTakePicture).Transfer
                oImage.SaveFile "myfilename.jpg"
           End If
        Next
    http://msdn.microsoft.com/library/en.../startpage.asp

  11. #11
    Registered User
    Join Date
    Nov 2003
    Posts
    12
    By the way, how can I create a file in VB directly? I have no idea about using VB using Visual Studio 6.0.

  12. #12
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    What's with all this VB on the C++ board?

    davidsk, take the VB example and find the equivalent C++ class libraries and use those in your C++ programs
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  13. #13
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    You'll have to give me more info. Is is it giving an error message? I'd suggest, instead of using a web page you paste this into a text file and save it with a .vbs extension, then double click to run:

    Code:
        Const wiaCommandTakePicture = "{AF933CAC-ACAD-11D2-A093-00C04F72DC3C}"
        Const CameraDeviceType = 2
    
    
        Set oDeviceManager = CreateObject("WIA.DeviceManager")
    
        For Each oDeviceInfo In oDeviceManager.DeviceInfos
           If oDeviceInfo.Type = CameraDeviceType Then
                Set oImage = oDeviceInfo.Connect.ExecuteCommand(wiaCommandTakePicture).Transfer
                oImage.SaveFile "myfilename.jpg"
           End If
        Next
    This should be easier to diagnose.

    >>src="wiaaut.vbs"><<

    Have you got this file? Assumably, this is meant to contain the constants.

  14. #14
    Registered User
    Join Date
    Nov 2003
    Posts
    12
    I didn't get any error report, but, anyhow, I got the solution after combining your code and WAI example codes. However, I got a new problem. I at moment have three wireless logitech webcams. When running the following program, it takes the same picture from the same camera. I suspect because the program has no time sleep to wait for the camera channels changed before taking a picture. On the other hand, the picture is very faint, how can I adjust its brightness.

    Here is my code:

    Code:
    Private Sub Command1_Click()
    Dim i As Integer
    
    For i = 1 To DeviceManager1.DeviceInfos.Count
        MsgBox DeviceManager1.DeviceInfos(i).Properties("Name").Value & vbCrLf & _
               "(" & DeviceManager1.DeviceInfos(i).DeviceID & ")"
               Dim picName As String
               picName = "pic " + CStr(i) + ".jpg"
               
    Set oImage = DeviceManager1.DeviceInfos(i).Connect.ExecuteCommand(wiaCommandTakePicture).Transfer
    
    oImage.SaveFile picName
    
    Next
    
    End Sub
    Last edited by davidsk; 12-05-2003 at 09:57 AM.

  15. #15
    Registered User
    Join Date
    Nov 2003
    Posts
    12
    Salem

    Sorry about that. I am looking for a solution. I would like to use C++, and, in fact, WIA supports C++ as well. Unfortunately, I am not good at C++. To be honest, I am good at Java, and just begin learning C++.

    Since, anonytmouse gave me a solution in VB and it also can be transfered to C++ using the special tool: B2C.exe.

    As you can see, I was looking for a solution in C++, so I posted this topic on this board.

    Anyhow, after a solution is found, anyone who would like to use C++ can use the special tool to transfer it into C++.

    Cheers

    David

    Originally posted by Salem
    What's with all this VB on the C++ board?

    davidsk, take the VB example and find the equivalent C++ class libraries and use those in your C++ programs
    Last edited by davidsk; 12-05-2003 at 08:33 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multiple Ports using Sockets
    By mmondok in forum C Programming
    Replies: 1
    Last Post: 04-14-2003, 09:36 PM
  2. Multiple Windows, One Program?
    By skyruler54 in forum C++ Programming
    Replies: 3
    Last Post: 10-12-2002, 08:29 PM
  3. multiple runs of a program
    By unregistered in forum Linux Programming
    Replies: 5
    Last Post: 03-15-2002, 07:18 AM
  4. Disabling multiple instances of a program
    By xds4lx in forum Windows Programming
    Replies: 6
    Last Post: 03-06-2002, 02:21 AM
  5. program that uses multiple funtions
    By mike in forum C++ Programming
    Replies: 5
    Last Post: 02-09-2002, 08:44 AM