I need a simple, but complete, example of capturing a snapshot from Logitech USB webcam in a console application, but I don't find.
The next instruction not works.
private Capture _capture = null; //Camera
Where is Capture definition? In the Emgu.CV.World not it is.
I use the 3.2.0 version of EmguCV.
http://www.emgu.com/wiki/index.php?title=Camera_Capture
Thank you in advance.
The error is the attached image
Did you read the entire article? It is instantiated here:
private void SetupCapture(int Camera_Identifier)
{
//update the selected device
CameraDevice = Camera_Identifier;
//Dispose of Capture if it was created before
if (_capture != null) _capture.Dispose();
try
{
//Set up capture device
_capture = new Capture(CameraDevice);
_capture.ImageGrabbed += ProcessFrame;
}
catch (NullReferenceException excpt)
{
MessageBox.Show(excpt.Message);
}
}
Hope this helps.
Doug
Related
I have a program in which I use the Aforge library for viewing a webcam.
This works wonder:
LocalWebcamsCollection = new FilterInfoCollection(FilterCategory.VideoInputDevice);
LocalScannerBarcode = new VideoCaptureDevice(LocalWebcamsCollection[WebcamNumber].MonikerString);
LocalScannerBarcode.NewFrame += LocalScannerBarcode_NewFrame;
LocalScannerBarcode.Start();
and in the new frame event I get the bitmap
System.Drawing.Bitmap frame;
void LocalScannerBarcode_NewFrame(object sender, AForge.Video.NewFrameEventArgs eventArgs)
{
frame = (System.Drawing.Bitmap)eventArgs.Frame.Clone();
}
now I have to decode what is seen. Basically I have to pass the bitmap to decode.
So global I have;
ZXing.BarcodeReader bcr;
and into the event LocalScannerBarcode_NewFrame
if (bcr == null)
bcr = new ZXing.BarcodeReader();
but as soon as I put the two lines above the event is not called anymore.
Please notice that in Windows forms that works but I have to do it in WPF.
Thanks
Not sure if this helps but have you tried putting the reference to the ZXing library in another project? Something an Helper.
So in you project you will have:
string strResult = Helper.ReadBarcode(frame);
if (strResult != null)
{
... do stuff with the string
}
and in the helper
static ZXing.BarcodeReader bcr;
public static string ReadBarcode(System.Drawing.Bitmap bmp)
{
if (bcr == null)
bcr = new ZXing.BarcodeReader();
return bcr.Decode(bmp).ToString();
}
I have an accord videoSourcePlayer control in my form.Why is it that it is not rendering the video that I select? Please see my code below:
// Open video file using DirectShow
private void openVideoFileusingDirectShowToolStripMenuItem_Click(object sender, EventArgs e)
{
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
// create video source
FileVideoSource = new FileVideoSource(openFileDialog.FileName);
// open it
sourceInitialiization = true;
OpenVideoSource(FileVideoSource);
}
}
// Open video source
private void OpenVideoSource(IVideoSource source)
{
// set busy cursor
this.Cursor = Cursors.WaitCursor;
// close previous video source
CloseVideoSource();
// start new video source
videoSourcePlayer.VideoSource = new AsyncVideoSource(source);
videoSourcePlayer.Start();
// reset statistics
statIndex = statReady = 0;
// start timers
timer.Start();
alarmTimer.Start();
//alarmTimer1.Start();
videoSource = source;
this.Cursor = Cursors.Default;
}
In my laptop where I initially coded this program, this works perfectly, but if I transfer it to another machine, say a desktop or another laptop, the code doesn't work anymore. It runs but it doesn't render the video and there is not error detected in the debugger too.
I tried downloading a sample video project from accord framework but I still couldn't get it to play a video on the desktop except on my laptop. What am I missing? Thank you.
Have you subscribed to the NewFrameReceived event?
I'm writing a program to save some webcam video to a file. I'm using the x264 codec found here x264.
When I try writing frames to a file I get this warning message poping up. It still records the video. But I don't want this popup showing on the screen.
x264vfw [warning]: Few frames probably would be lost. Ways to fix this:
x264vfw [warning]: -if you use VirtualDub or its fork than you can enable 'VirtualDub Hack' option
x264vfw [warning]: -you can enable 'File' output mode
x264vfw [warning]: -you can enable 'Zero Latency' option
Is there anyway to config "File ouput mode" or "Zero Latency" by using C# or C++ or command line?
This is the code:
public static void StartCapture()
{
try
{
capture = new Capture();
capture.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_WIDTH, 1920); //1920
capture.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_HEIGHT, 1080); //1080
CaptureOutput = new VideoWriter
(
"capture output.avi",
CvInvoke.CV_FOURCC('X','2','6','4'),
50, //fps
(int)capture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_WIDTH),
(int)capture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_HEIGHT),
true
);
if (capture != null)
{
capture.ImageGrabbed += SaveFrame;
capture.Start();
}
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}
static void SaveFrame(System.Object sender, EventArgs e)
{
Image<Bgr, Byte> video;
video = capture.RetrieveBgrFrame();
CaptureOutput.WriteFrame(video);
}
I'm having some trouble using ZXing in silverlight.
I'm using this ZXing port: http://zxingnet.codeplex.com/
My proejct is able to get the video feed from the webcam, but I'm stuck at this line.
This is how i get the feed:
CaptureSource _capture = new CaptureSource();
_capture.VideoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice();
videoBrush = new VideoBrush();
videoBrush.Stretch = Stretch.Uniform;
videoBrush.SetSource(_capture);
webcam.Fill = videoBrush;
if (CaptureDeviceConfiguration.AllowedDeviceAccess||CaptureDeviceConfiguration.RequestDeviceAccess())
{
try
{
_capture.Start();
}
catch (Exception E)
{
MessageBox.Show(E.Message);
}
}
LuminanceSource source = new RGBLuminanceSource(,webcam.Width, webcam.Height);
It says, that says that it need a byte array, the "rbgRawBytes".
I got a videobrush which contains the webcam stream, i think :)
and i got the webcam rectangle that displays the output.
You should use the method CaptureImageAsync and the event CaptureImageCompleted. In the event handler you get a WriteableBitmap within the event arguments. The WriteableBitmap is a captured image from the webcam. Use the WriteableBitmap instance directly with the method Decode of the BarcodeReader class. Don't do it manually by using RGBLuminanceSource.
Here is a good sample how you can use CaptureImageAsync and CaptureImageCompleted:
http://channel9.msdn.com/coding4fun/articles/FaceLight--Silverlight-4-Real-Time-Face-Detection
How would I go about capturing one frame from a feed of video from a webcam or video capture card in C#? I want to display the live feed and have a method that takes one frame and saves it to a remote server either via FTP or over a shared network path.
If you are able to streaming live video, then you can capture the live video stream just click on button by this code:
private Capture capture = null;
private void btnStart_Click(object sender, System.EventArgs e)
{
try
{
if ( capture == null )
throw new ApplicationException( "Please select a video and/or audio device." );
if ( !capture.Cued )
capture.Filename = txtFilename.Text;
capture.Start();
btnCue.Enabled = false;
btnStart.Enabled = false;
}
catch (Exception ex)
{
MessageBox.Show( ex.Message + "\n\n" + ex.ToString() );
}
}
You could use OpenCV. If you search on StackOverflow you'll find a lot of source on how to do that.
There's even .NET wrappers for OpenCV like opencvdotnet and Emgu CV.
You will probably end up using a few functions from the library, such as cvCaptureFromCAM() and cvQueryFrame().