Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I scan every frame from ISampleGrabber using directshow.net
    primarykey
    data
    text
    <p>I have a program which currently displays a preview of a usb webcam and then displays a frame within a picturebox when a button is pressed. This is done by using the directshow DxSnap sample thus using the ISampleGrabberCB interface.</p> <p>Would it be possible for each frame to be scanned automatically without the use of a button?</p> <p>I tried to do this with a timer however the result ended with bad image quality from both preview and the captured image.</p> <p>Would this be achieved by using the IsampleGrabberCB.BufferCB function?</p> <p>The way I am currently getting frames using is a button consists of:</p> <pre><code>int ISampleGrabberCB.BufferCB(double sampleTime, IntPtr buffer, int bufferLength) { Debug.Assert(bufferLength == Math.Abs(pitch) * videoHeight, "Wrong Buffer Length"); if (gotFrame) { gotFrame = false; Debug.Assert(imageBuffer != IntPtr.Zero, "Remove Buffer"); CopyMemory(imageBuffer, buffer, bufferLength); pictureReady.Set(); } return 0; } public void getFrameFromWebcam() { if (iPtr != IntPtr.Zero) { Marshal.FreeCoTaskMem(iPtr); iPtr = IntPtr.Zero; } //Get Image iPtr = sampleGrabberCallBack.getFrame(); Bitmap bitmapOfFrame = new Bitmap(sampleGrabberCallBack.width, sampleGrabberCallBack.height, sampleGrabberCallBack.capturePitch, PixelFormat.Format32bppRgb, iPtr); bitmapOfFrame.RotateFlip(RotateFlipType.RotateNoneFlipY); pictureBox3.Image = bitmapOfFrame; barcodeReader(bitmapOfFrame); } public IntPtr getFrame() { int hr; pictureReady.Reset(); imageBuffer = Marshal.AllocCoTaskMem(Math.Abs(pitch) * videoHeight); try { gotFrame = true; if (videoControl != null) { hr = videoControl.SetMode(stillPin, VideoControlFlags.Trigger); DsError.ThrowExceptionForHR(hr); } if (!pictureReady.WaitOne(9000, false)) { throw new Exception("Timeout waiting to get picture"); } } catch { Marshal.FreeCoTaskMem(imageBuffer); imageBuffer = IntPtr.Zero; } return imageBuffer; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload