I have made a picturebox and a coding witch takes a picture in the picturebox, but the problem is that I need to save it as a image file before I can use getpixel, so when I use a save picturebox as image then VB.NET returns an error with image not exists,
11 3764
Can you show us what you've attempted so far, that doesn't work?
I know what Patr's talking about, and I'd like to know how to do this too.
Debasisdas has made an example of how to capture from a webcam and "display the live video in a picturebox". However, what Windows is actually doing is displaying the picture on top of the picture box (known as overlaying). Therefore the picturebox actually still is empty, meaning that GetPixel() will fail to give back colours of the camera's images, and SavePicture() will obviously also fail to save the images.
We need a way to actually set the contents of the picturebox, and the easiest way seems to be by saving an image from the camera and loading it into the picturebox, where it can then be used as any other loaded image file. The downside to this is that the frame rate would probably be very low (probably no more than 4 fps or so) due to overheads from the file system (or possibly the hard disk itself, reading/writing the file over and over).
EDIT: I'm using VB6 and Windows XP, by the way, and this still happens. However, I tried using MCI to play a video in a picture box (this being related to webcams because MCI also just overlays in XP), on an extremely old computer running Windows 98, and GetPixel() worked - I think that may be because GetPixel() works differently on 98 compared to XP, rather than anything else.
EDIT2: Stupidly, it didn't occur to me at the time to try SavePicture(), which would confirm whether it was just GetPixel() being different on 98, or if 98 was actually placing the picture into the picturebox
.
that is exactly what I am talking about.
Thanks for the input, Robbie.
I don't know the answer, but it occurs to me there may be another workaround. Not a really elegant way to go, but possibly faster. That is, use the API call (I forget the details, this is probably going back over 5 years) which is typically used by screensavers to grab the desktop.
When you write a screensaver, typically the first thing you do (at least in the simple examples I coded, way back) is to grab a snapshot of the current display, so you can play with it. It should be possible either do this then throw away the part you don't want, or if possible, grab just the part where your picturebox lives.
If interested, you should be able to find plenty of examples by searching for info on VB and screen savers.
Ok ok the answer is actually very simple. i made an instant messanger with webcam and voice about a year ago. for the image thing just get the handle of the picturebox.
camHwnd = capCreateCaptureWindow(CamWnd, 0, 0, 0, 320, 240, me.hwnd, 0)
Then all you have to do is save like this:
SavePicture Picture1.picture, Path
Then Reload the picture like this:
Picture1.picture = loadpicture(path )
thats is.
if thats what you were doing that should werk. im testing right now and after getting the picture reloaded into the picturebox i am able to use getpixel function on it.
P.S. the frame rate on my webcam is about twice as good as the frame rate of yahoo instant messanger's webcam. my computer specs. are: xp pro, AMD 64 moblie Athlon, 1gig ram. like i said the saving and opening of the image does slow the framerate but if you broad casting over the internet your fps will well over exceed your streaming speeds.
Hi, I'm having the exact same problem. I am trying to detect certain pixels from a video streaming from a webcam (don't really need to detect the entire webcam image, just 10 or 20 pixels of it to see if they change).
But I can't get it working! I've followed this thread and this is the code I've ended up with:
This is the code in a module (.bas file): -
Option Explicit
-
-
Public Const ws_child As Long = &H40000000
-
Public Const ws_visible As Long = &H10000000
-
Global Const WM_USER = 1024
-
Global Const wm_cap_driver_connect = WM_USER + 10
-
Global Const wm_cap_set_preview = WM_USER + 50
-
Global Const WM_CAP_SET_PREVIEWRATE = WM_USER + 52
-
Global Const WM_CAP_DRIVER_DISCONNECT As Long = WM_USER + 11
-
Public Const WM_CAP_DLG_VIDEOFORMAT As Long = WM_USER + 41
-
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
-
Declare Function capCreateCaptureWindow Lib "avicap32.dll" Alias "capCreateCaptureWindowA" (ByVal a As String, ByVal b As Long, ByVal c As Integer, ByVal d As Integer, ByVal e As Integer, ByVal f As Integer, ByVal g As Long, ByVal h As Integer) As Long
-
This is the code in my form: - Option Explicit
-
'General Declaration
-
Dim hwdc As Long
-
Dim startcap As Boolean
-
-
Private Sub cmdCapture_Click()
-
Dim temp As Long
-
-
hwdc = capCreateCaptureWindow("Debasis Das", ws_child Or ws_visible, 0, 0, 320, 240, Picture1.hWnd, 0)
-
If (hwdc <> 0) Then
-
temp = SendMessage(hwdc, wm_cap_driver_connect, 0, 0)
-
temp = SendMessage(hwdc, wm_cap_set_preview, 1, 0)
-
temp = SendMessage(hwdc, WM_CAP_SET_PREVIEWRATE, 30, 0)
-
startcap = True
-
Else
-
MsgBox ("No Webcam found")
-
End If
-
End Sub
-
-
Private Sub cmdClose_Click()
-
Dim temp As Long
-
If startcap = True Then
-
temp = SendMessage(hwdc, WM_CAP_DRIVER_DISCONNECT, 0&, 0&)
-
startcap = False
-
End If
-
End Sub
-
-
Private Sub cmdexit_Click()
-
Unload Me
-
End Sub
-
-
Private Sub cmdVideoFormat_Click()
-
Dim temp As Long
-
If startcap = True Then
-
temp = SendMessage(hwdc, WM_CAP_DLG_VIDEOFORMAT, 0&, 0&)
-
End If
-
End Sub
-
-
-
Private Sub Timer1_Timer()
-
Dim camwnd As String
-
Dim CamHwnd As String
-
Dim Path As String
-
- camwnd = Me.hWnd
- CamHwnd = capCreateCaptureWindow(camwnd, 0, 0, 0, 320, 240, Me.hWnd, 0)
-
-
Path = "C:\Test.jpg"
-
-
SavePicture Picture1.Picture, Path
-
Picture1.Picture = LoadPicture(Path)
-
-
Me.lblColor = Me.Picture1.Point(100, 100) 'Just a test, trying to get a pixel value
-
End Sub
-
The idea is that the timer will periodically (several times per second) check some pixel (in this example at x=100, y=100) and for now just print the value of this pixel in a label in the form.
But the program crashes at the SavePicture line, saying "Invalid property value", and then VB6 itself crashes.
I think that we're really close here. I've tried to fill the "camwnd" variable with both the name and hWnd of both the form and the picturebox, but there's no difference in the outcome.
Does anyone know how I can get the value of certain pixels in the video stream (preferrably without having to save it to a file and load it again)?
Thanks. :-)
Well, I just made the strangest breakthrough.
I removed the saving and loading of the image file, and replaced "Picture1.hwnd" with "Me.HWnd" in the capCreateCaptureWindow command at line 9 in my code, and... it works!!!
I have no idea why or how, but it works. The image is now drawn directly on the form's surface, and I can still use Me.Picture1.Point to get the value, which can then be split up in it's Red, Green and Blue components.
But I had to move the picturebox to position 0,0 (upper left corner in the form) and make it the same size as the picture from the webcam (320x240 pixels in my case). I also set the ScaleMode of both the form and picturebox to "Pixel".
I really don't have any idea why this works, but I don't really care as long as it does. :-)
BTW, if anyone's interested, this is the sub I use to get Red, Green and Blue from the color value: -
Public Function get_rgb(Color, rd, gr, bl)
-
Dim tmpColor
-
If Color < 0 Then Color = 0
-
-
tmpColor = Color / 65536
-
bl = Int(tmpColor)
-
tmpColor = (tmpColor - Int(tmpColor)) * 256
-
-
gr = Int(tmpColor)
-
tmpColor = (tmpColor - Int(tmpColor)) * 256
-
-
rd = Round(tmpColor)
-
End Function
-
You put in the color you get from the webcam (Long data type), and three variables for Red, Green, and Blue (normally data type Byte). These variables will then be filled with RGB values.
Thanks for sharing that with us, rfoshaug. I've had to split colours like this a few times, too. I'd like to make a couple of small comments about this version. - Ideally, you should work with Long data type wherever possible, for performance reasons. It might seem crazy, but it's actually slightly faster to work with Long than with Byte. (On a 32 bit system, that is. 64 bit may be different).
- Integer division is faster, too. Try using \ instead of /.
- You're doing the same calculation twice, unnecessarily. In line 7, for instance, you should use bl rather than Int(tmpColor).
This is all just nitpicking, of course - if the routine works, great. :)
EDIT: Oops! The integer division thing (\) might not work with your method.
I've just discovered that these lines:
camwnd = Me.hWnd
CamHwnd = capCreateCaptureWindow(camwnd, 0, 0, 0, 320, 240, Me.hWnd, 0)
are not needed in the timer sub, and actually cause lockups and problems, so I'm removing them from the code in my earlier post.
Edit: It seems I can't edit that older post. Anyway, it's line 45 and 46 in the first code I posted, in the Timer sub.
I've just discovered ....
I've edited it and put those two lines in italics. At least they will look slightly different, so when people get to this message they should know which lines you mean.
It might be better to just use the Reply function to copy the code from that message and re-post it here without those lines.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Kelowna |
last post by:
Yes... Its a server os... i kno! i hav xp yea but tis system is for screwing
with.. Im sure theres alot of ppl here tat kno tis stuff inside-out! im
doing this for educational purposes so dont give...
|
by: Joakim Rylander |
last post by:
Hi all,
I need to create a public booth where people can look at themselves in a
webcam and snap a picture which will be seen on a webpage. The backend is
easy, it's the webcam part that I have...
|
by: Elp |
last post by:
Hi,
We have developped an client application in C#. Among other things, this
application should display in
4 different windows (or 4 different panels in the same window), 4 webcam
streams (web...
|
by: Mathieu Chavoutier |
last post by:
Hi.
Is it possible to do a program that show the "film" that is currently on our
webcam ?
I do not have a Webcam for the moment, so, if you have advices to chose a
Webcam compliant (with what...
|
by: Steve |
last post by:
Hi
Can anyone please tell me how to use a webcam on a form. I have done an app
that uses a webcam, but I have used the drivers for that webcam. Now I need
to use a different camera on a...
|
by: Pat Mac |
last post by:
Hopefully this is a good group to ask this question. I'm trying to
programmatically control a micro innovations IC50C webcam with VB.NET.
Specifically I'm using the Kodak scanner control. My...
|
by: DillonCzerny |
last post by:
Hello
Many times I see a lot of people post webcam videos on google video or youtube. I wonder how do they record it from those people’s webcam? I have a fake webcam and I want to record some...
|
by: Berco Beute |
last post by:
I've been trying to access my webcam using Python, but I failed
miserably. The camera works fine under Ubuntu (using camora and
skype), but I am unable to get WebCamSpy or libfg to access my...
|
by: frakie |
last post by:
Hi there,
I need a simple and stupid few line source code to access my webcam.
I found lots of huge projects (c++ c and other) which are so big that
they are impossible to be used.
Does somebody...
|
by: Steve |
last post by:
Hi All
I have a VB.net 2005 windows forms application which uses webcam to take
photos of staff members etc for use within the application
All works fine if an external webcam is used
The...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |