Page 1 of 1

Use Default Camera

PostPosted: Mon Jun 03, 2019 9:59 pm
by eblancovitch
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

Re: Use Default Camera

PostPosted: Tue Jun 04, 2019 8:00 am
by andrew.kirillov
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.