The MP3car.com Store  

Welcome to the MP3Car.com forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. Registering will also remove advertisements. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

Go Back   MP3Car.com > Mp3Car Technical > Software & Software Development

Reply
 
Thread Tools Display Modes
Old 02-28-2008, 01:32 PM   #1
Constant Bitrate
portreathbeach's CarPC Specs
 
Join Date: Sep 2006
Location: Cornwall, England
Vehicle: 2003 VW Transporter T5
Posts: 145
My Photos: (46)
Webcam mirror/flip VB.NET help please?

Hi,

I want to add a reversing cam to my project. I have some sample VB.NET code that uses avicap32.dll to 'get' the webcam and then opens a preview window in a picturebox on a form. Using a few Sendmessage commands, the webcam image is displayed in the picturebox.

Everything works nicely apart from I would like the image to be flipped/mirrored, as it were if you were using a rear view mirroe. Is there any commands you have to 'send' the webcam via avicap32, or is it more complicated than that?

Thanks
__________________
ViVE - Volkswagen In Van Entertainment:

VoomPC 2, VIA C7 2GHz
7" Lilliput
120Gb Sata drive
1GB RAM


[||||||||||] 100% - Planning
[||||||||||] 100% - Software coding
[||||||||||] 100% - Built

(Always tweaking!)
portreathbeach is offline   Reply With Quote
Sponsored Links
Old 02-28-2008, 03:44 PM   #2
Constant Bitrate
Ineffigy's CarPC Specs
 
Join Date: Apr 2006
Location: Dallas, Texas
Vehicle: 2005 Toyota Celica GTS 6
Posts: 220
My Photos: (0)
What format is the video when you get it from the WebCam? You might be able to flip the X,Y coords of the image on-the-fly.
Ineffigy is offline   Reply With Quote
Old 02-28-2008, 03:58 PM   #3
Constant Bitrate
Ineffigy's CarPC Specs
 
Join Date: Apr 2006
Location: Dallas, Texas
Vehicle: 2005 Toyota Celica GTS 6
Posts: 220
My Photos: (0)
http://www.codeproject.com/KB/audio-...ctShowNET.aspx

Here's some code that allows you to grab the webcam information.

Check out this article to see the image inversion..

http://forums.microsoft.com/MSDN/Sho...13689&SiteID=1
Ineffigy is offline   Reply With Quote
Old 02-28-2008, 05:35 PM   #4
Constant Bitrate
portreathbeach's CarPC Specs
 
Join Date: Sep 2006
Location: Cornwall, England
Vehicle: 2003 VW Transporter T5
Posts: 145
My Photos: (46)
Thanks for the reply, this is the code that I've just got working. It's basic, but it works, and I'll probably build on it...



Imports System.Runtime.InteropServices


Public Class Form1

Const WM_CAP As Short = &H400S
Const WM_CAP_DRIVER_CONNECT As Integer = WM_CAP + 10
Const WM_CAP_DRIVER_DISCONNECT As Integer = WM_CAP + 11
Const WM_CAP_EDIT_COPY As Integer = WM_CAP + 30
Const WM_CAP_SET_PREVIEW As Integer = WM_CAP + 50
Const WM_CAP_SET_PREVIEWRATE As Integer = WM_CAP + 52
Const WM_CAP_SET_SCALE As Integer = WM_CAP + 53
Const WS_CHILD As Integer = &H40000000
Const WS_VISIBLE As Integer = &H10000000
Const SWP_NOMOVE As Short = &H2S
Const SWP_NOSIZE As Short = 1
Const SWP_NOZORDER As Short = &H4S
Const HWND_BOTTOM As Short = 1
'--------------------------------------------------
Const WM_CAP_CONNECT As Integer = 1034
Const WM_CAP_DISCONNECT As Integer = 1035
Const WM_CAP_GET_FRAME As Integer = 1084
Const WM_CAP_COPY As Integer = 1054


Private tempObj As IDataObject
Private tempimg As System.Drawing.Bitmap
Private mCapHwnd As Integer ' Handle of webcam
Dim iDevice As Integer = 0 ' Current device ID


Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, _
<MarshalAs(UnmanagedType.AsAny)> ByVal lParam As Object) As Integer

Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos" (ByVal hwnd As Integer, _
ByVal hWndInsertAfter As Integer, ByVal x As Integer, ByVal y As Integer, _
ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer) As Integer

Declare Function DestroyWindow Lib "user32" (ByVal hndw As Integer) As Boolean

Declare Function capCreateCaptureWindowA Lib "avicap32.dll" _
(ByVal lpszWindowName As String, ByVal dwStyle As Integer, _
ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, _
ByVal nHeight As Short, ByVal hWndParent As Integer, _
ByVal nID As Integer) As Integer

Declare Function capGetDriverDescriptionA Lib "avicap32.dll" (ByVal wDriver As Short, _
ByVal lpszName As String, ByVal cbName As Integer, ByVal lpszVer As String, _
ByVal cbVer As Integer) As Boolean



Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click

Try
' setup a capture window
mCapHwnd = capCreateCaptureWindowA("WebCap", 0, 0, 0, 320, 240, Me.Handle.ToInt32(), 0)

' connect to the capture device
SendMessage(mCapHwnd, WM_CAP_CONNECT, iDevice, 0)
SendMessage(mCapHwnd, WM_CAP_SET_PREVIEW, iDevice, 0)

'Set the preview rate in milliseconds
SendMessage(mCapHwnd, WM_CAP_SET_PREVIEWRATE, 40, 0)

Catch ex As Exception
DestroyWindow(mCapHwnd)
End Try

Timer1.Enabled = True
End Sub


Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click

' Disconnect device
SendMessage(mCapHwnd, WM_CAP_DISCONNECT, iDevice, 0)
Timer1.Enabled = False
End Sub


Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
DestroyWindow(mCapHwnd)
End Sub


Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

Try

' get the next frame;
SendMessage(mCapHwnd, WM_CAP_GET_FRAME, 0, 0)

' copy the frame to the clipboard
SendMessage(mCapHwnd, WM_CAP_COPY, 0, 0)

' get from the clipboard
tempObj = Clipboard.GetDataObject()
tempimg = tempObj.GetData(System.Windows.Forms.DataFormats.B itmap)
tempimg.RotateFlip(RotateFlipType.RotateNoneFlipX)

PictureBox.Image = tempimg

Catch ex As Exception
End Try
End Sub
End Class



All I do is copy a frame to the clipboard from the camera every time the timer ticks. I then copy and flip the image to a tempory image object and then put the image in the image box.

Seems to work OK, do you think this is a good method?
__________________
ViVE - Volkswagen In Van Entertainment:

VoomPC 2, VIA C7 2GHz
7" Lilliput
120Gb Sata drive
1GB RAM


[||||||||||] 100% - Planning
[||||||||||] 100% - Software coding
[||||||||||] 100% - Built

(Always tweaking!)
portreathbeach is offline   Reply With Quote
Old 02-28-2008, 10:22 PM   #5
Constant Bitrate
Ineffigy's CarPC Specs
 
Join Date: Apr 2006
Location: Dallas, Texas
Vehicle: 2005 Toyota Celica GTS 6
Posts: 220
My Photos: (0)
Well, I am used to C# more so I'll try to translate. Basically you'll be doing the same thing, only you won't be using the clipboard since that can screw with other applications.

The basic idea is to create a call back function (handler) so that every time an image is captured from the card, you can flip it.

I started to try and convert it all to VB.NET from C#.NET but there is just too much I would need to define, instead I'll direct you to the C# code. I'm sure you can translate it as the languages are pretty similar.

http://www.codeproject.com/KB/audio-...?display=Print

If you need help with converting anything I should be able to do it for you. I'm just more confortable using C#.

Last edited by Ineffigy : 02-28-2008 at 10:23 PM. Reason: Update
Ineffigy is offline   Reply With Quote
Old 02-29-2008, 03:32 PM   #6
Constant Bitrate
portreathbeach's CarPC Specs
 
Join Date: Sep 2006
Location: Cornwall, England
Vehicle: 2003 VW Transporter T5
Posts: 145
My Photos: (46)
Cheers. But I tried this and it keeps crashing.

The code I have seems to work OK. Just need to buy another webcam and an extender cable and try it out!


Cheers
__________________
ViVE - Volkswagen In Van Entertainment:

VoomPC 2, VIA C7 2GHz
7" Lilliput
120Gb Sata drive
1GB RAM


[||||||||||] 100% - Planning
[||||||||||] 100% - Software coding
[||||||||||] 100% - Built

(Always tweaking!)
portreathbeach is offline   Reply With Quote
Sponsored Links
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Logitech Orbit AF Webcam hardcoreracing Road Runner 2 02-16-2008 10:53 PM
Experimenting with Dash Cam. Should I convert my webcam to infrared? nobb General Hardware Discussion 1 02-16-2008 08:56 PM
Webcam Options jschrauwen Input Devices 11 01-04-2008 12:15 PM
FAQ: How To Make An IR Webcam rijndael The FAQ Emporium 1 09-03-2007 01:35 PM
VB.net and FMOD bondbond55 Software & Software Development 0 03-12-2004 10:56 AM


All times are GMT -5. The time now is 08:38 PM.


Sponsored Links
The MP3car.com Store

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.1.0
Copyright © 1999 - 2008 Mp3Car.com Inc.
Ad Management by RedTyger
Message Board Statistics