AForge.NET

  :: AForge.NET Framework :: Articles :: Forums ::

Use Default Camera

Forum to discuss AForge.NET Framework, its features, API, how-tos, etc.

Use Default Camera

Postby eblancovitch » Mon Jun 03, 2019 9:59 pm

Im new to this forum and also new to AForge.net this is an awesome tool.. i really love it..
I have created a small app to get images from the camera, my laptop has 1 camera, but my wife has 2 cameras front and back.

I will like to use by default rear camera, and get a small resolution by default

This is my code..
Try
Dim pcCameras As VideoCaptureDeviceForm = New VideoCaptureDeviceForm()
Dim resolution As String = ""
Dim resolution_size As String = ""
' WHY ASK EVERY TIME IF THERE IS ONLY 1 CAMERA
If pcCameras.ShowDialog() = DialogResult.OK Then
devCamera = pcCameras.VideoDevice
devCamera.VideoResolution = devCamera.VideoCapabilities(0)
'--------------
devCamera.VideoCapabilities.Count
For i As Integer = 0 To devCamera.VideoCapabilities.Count - 1
resolution = "Resolution Number " & Convert.ToString(i)
resolution_size = devCamera.VideoCapabilities(i).FrameSize.ToString()
Next
'--------------
AddHandler devCamera.NewFrame, New NewFrameEventHandler(AddressOf CaptureImage)
devCamera.Start()
Else
Me.Close()
End If
Catch ex As Exception
MessageBox.Show(ex.ToString(), ProgName, MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try

1) i will like that if there are more than 1 camera it should ASK.. but if only one camera why ask?
2) if i have more than 1 camera, use the rear by default
3) select a small resolution by default..

I will not like to see the camera dialog, i want to do this from code
eblancovitch
 
Posts: 1
Joined: Mon Jun 03, 2019 9:51 pm

Re: Use Default Camera

Postby andrew.kirillov » Tue Jun 04, 2019 8:00 am

eblancovitch wrote:I will not like to see the camera dialog, i want to do this from code

You can check number of cameras and chose the one you like from code. However, there is nothing which tells if the camera is front or rear. At least not with DirectShow API, which is used by AForge.NET Framework.

As for resolution - again you can check supported resolutions and chose the one you like.
With best regards,
Andrew


Interested in supporting AForge.NET Framework?
User avatar
andrew.kirillov
Site Admin, AForge.NET Developer
 
Posts: 3427
Joined: Fri Jan 23, 2009 9:12 am
Location: UK




Return to AForge.NET Framework

cron