1 second video stream latency occurred with Emgu CV - c#

I have a sight line decoder device connected to my PC via Ethernet.
I used Emgucv to capture the video stream and view it in an image box.
Here is part of the code:
_capture = new Capture("udp://#169.254.1.144:15004");
_capture.ImageGrabbed += ProcessFrame;
Image<Bgr, Byte> frame,frame1;
private void ProcessFrame(object sender, EventArgs arg)
{
frame = _capture.RetrieveBgrFrame();
pictureBox1.Image = frame.ToBitmap();
}
The video viewed in the Imagebox, but with 1 sec latency; I counted the frame reached the ProcessFramefunction and its 12fps and its correct;
Does the ImageGrabbed event cause this latency?
Why does the latency occur?
Note : I used an usb camera instead the sightline and worked fine; also the sightline plus which can play the camera via Ethernet works fine too.

This is caused by the length of the default buffer used by the 'Capture' object. Raw OpenCV has a 'CV_CAP_PROP_BUFFERSIZE' flag you can set to alter this value using .set()

Related

Decrease or compress audio quality in CSCORE

I am creating an application which streams audio over UDP. Currently it works fine, however it uses alot of network usage (upto 500kbps). Is this normal? Is there a way I can compress or slightly reduce the quality of the audio so it uses up less network usage?
WasapiCapture capture = new WasapiLoopbackCapture();
capture.Initialize();
capture.Start();
capture.DataAvailable += (object sender, DataAvailableEventArgs e) =>
{
// Send data here (works fine)
};
Yes this is normal. Its capturing at the default rate. You need to set your bitrate and codec.
This is what I am doing:
_soundIn = new WasapiLoopbackCapture(0, new CSCore.WaveFormat(44100, 16, 1, CSCore.AudioEncoding.MpegLayer3));

Screen recording as video, audio on SharpAvi - Audio not recording

Requirement:
I am trying to capture Audio/Video of windows screen with SharpAPI Example with Loopback audio stream of NAudio Example.
I am using C#, wpf to achieve the same.
Couple of nuget packages.
SharpAvi - forVideo capturing
NAudio - for Audio capturing
What has been achieved:
I have successfully integrated that with the sample provided and I'm trying to capture the audio through NAudio with SharpAPI video stream for the video to record along with audio implementation.
Issue:
Whatever I write the audio stream in SharpAvi video. On output, It was recorded only with video and audio is empty.
Checking audio alone to make sure:
But When I try capture the audio as separate file called "output.wav" and It was recorded with audio as expected and can able to hear the recorded audio. So, I'm concluding for now that the issue is only on integration with video via SharpApi
writterx = new WaveFileWriter("Out.wav", audioSource.WaveFormat);
Full code to reproduce the issue:
https://drive.google.com/open?id=1H7Ziy_yrs37hdpYriWRF-nuRmmFbsfe-
Code glimpse from Recorder.cs
NAudio Initialization:
audioSource = new WasapiLoopbackCapture();
audioStream = CreateAudioStream(audioSource.WaveFormat, encodeAudio, audioBitRate);
audioSource.DataAvailable += audioSource_DataAvailable;
Capturing audio bytes and write it on SharpAvi Audio Stream:
private void audioSource_DataAvailable(object sender, WaveInEventArgs e)
{
var signalled = WaitHandle.WaitAny(new WaitHandle[] { videoFrameWritten, stopThread });
if (signalled == 0)
{
audioStream.WriteBlock(e.Buffer, 0, e.BytesRecorded);
audioBlockWritten.Set();
Debug.WriteLine("Bytes: " + e.BytesRecorded);
}
}
Can you please help me out on this. Any other way to reach my requirement also welcome.
Let me know if any further details needed.
Obviously, author doesn't need it, but since I run to the same problem others might need it.
Problem in my case was that I was getting audio every 0.1 seconds and attempted to write both new video and audio at the same time. And getting new video data (taking screenshot) took me too long. Causing each frame was added every 0.3 seconds instead of 0.1. And that caused some problems with audio stream being not sync with video and not being played properly by video players (or whatever it was). And after optimizing code a little bit to be within 0.1 second, the problem is gone

Detect pause in SerialPort input

In my application, any phone can voice-connect to my 3G USB modem and the call gets picked up immediately. It receives audio as PCM (8000 samples, 16 bits, mono) through a serial port and uses Microsoft's Speech Synthesizer to talk back to the caller.
The problem is, the application should talk back only when the caller has stopped speaking. How can I detect that ?
I tried implementing a 3-second timer which resets itself when data is received from the serial port, so when the timer gets 'ticked' it should mean that that the caller was silent for 3 seconds. But it doesn't work that way. What did I do wrong ?
private void DataRecdFromSerial(object sender, SerialDataReceivedEventArgs e)
{
say.Stop(); say.Start(); // reset timer with interval 5000
int n = usb.BytesToRead;
byte[] comBuffer = new byte[90000];
usb.Read(comBuffer, 0, n);
if(comBuffer.Length > 0)
{
wfw.Write(comBuffer, 0, n); // NAudio Wave File Writer
}
}
private void say_Tick(object sender, EventArgs e)
{
// Caller stopped speaking for 5 seconds (not working)
}
By what magic on earth should data flow interrupt when there is silence ? you will get a continuous stream as long as the line is connected that is the most logical of all software and electronical engineering implementation that one can excpect today. So you need to analyze the spectrum of the sound wave and calculate root mean square amplitude to get energy. you compare to a threshold that you fix by empirical testing (because silence is actually a small noise that you need to accept).

C# -Application hang after connected with IP Camera

I am developing an application to show video using webcam and IpCamera.
For IpCamera, it shows video stream for sometime but after that it stops streaming and application hangs.
I am using Emgu.CV Library to grab frames and show it in the picture control.
I have tried below code for display of video by using function QueryFrame().
for connecting Ip camera
Capture capture = new Capture(URL);
for grabbing frames
Image<Bgr, Byte> ImageFrame = capture.QueryFrame();
After some time the QueryFrame() provide null value and application hangs.
Can any one tell me why this is happening and how I can handle it?
Thank you in advance.
Sorry about the delay but I have provide an example that works with several public IP cameras. It will need the EMGU reference replacing with your current version and the target build directory should be set to "EMGU Version\bin" alternatively extract it to the examples folder.
http://sourceforge.net/projects/emguexample/files/Capture/CameraCapture%20Public%20IP.zip/download
Rather than using the older QueryFrame() method it uses the RetrieveBgrFrame() method. It has worked reasonably well and I have had no null exceptions. However if you do replace the ProcessFrame() method with something like this
private void ProcessFrame(object sender, EventArgs arg)
{
//If you want to access the image data the use the following method call
//Image<Bgr, Byte> frame = new Image<Bgr,byte>(_capture.RetrieveBgrFrame().ToBitmap());
if (RetrieveBgrFrame.Checked)
{
Image<Bgr, Byte> frame = _capture.RetrieveBgrFrame();
//because we are using an autosize picturebox we need to do a thread safe update
if(frame!=null) DisplayImage(frame.ToBitmap());
}
else if (RetrieveGrayFrame.Checked)
{
Image<Gray, Byte> frame = _capture.RetrieveGrayFrame();
//because we are using an autosize picturebox we need to do a thread safe update
if (frame != null) DisplayImage(frame.ToBitmap());
}
}
Cheers
Chris

problem with download picture from canon camera to pc

i connected a eos canon camera to pc
i have an application that i could take picture remotly ,and download image to pc,
but when i remove the SD card from camera , i cant download image from buffer to pc
// register objceteventcallback
err = EDSDK.EdsSetObjectEventHandler(obj.camdevice, EDSDK.ObjectEvent_All, objectEventHandler, new IntPtr(0));
if (err != EDSDK.EDS_ERR_OK)
Debug.WriteLine("Error registering object event handler");
///
public uint objectEventHandler(uint inEvent, IntPtr inRef, IntPtr inContext)
{
switch(inEvent)
{
case EDSDK.ObjectEvent_DirItemCreated:
this.getCapturedItem(inRef);
Debug.WriteLine("dir item created");
break;
case EDSDK.ObjectEvent_DirItemRequestTransfer:
this.getCapturedItem(inRef);
Debug.WriteLine("file transfer request event");
break;
default:
Debug.WriteLine(String.Format("ObjectEventHandler: event {0}", inEvent));
break;
}
return 0;
}
anyone could help me , why this event does not call ,
or how i download image from buffer to pc, with out have Sd card on my camera
thanks
You probably ran into the same problem as I did yesterday: the camera tries to store the image for a later download, finds no memory card to store it to and instantly discards the image.
To get your callback to fire, you need to set the camera to save images to the PC (kEdsSaveTo_Host) at some point during your camera initialization routine. In C++, it worked like this:
EdsInt32 saveTarget = kEdsSaveTo_Host;
err = EdsSetPropertyData( _camera, kEdsPropID_SaveTo, 0, 4, &saveTarget );
You probably need to build an IntPtr for this. At least, that's what Dmitriy Prozorovskiy did (prompted by a certain akadunno) in this thread.
The SDK (as far as I know) only exposes the picture taking event in the form of the object being created on the file system of the camera (ie the SD card). There is not a way of which I am familiar to capture from buffer. In a way this makes sense, because in an environment where there is only a small amount of onboard memory, it is important to keep the volatile memory clear so that it can continue to take photographs. Once the buffer has been flushed to nonvolatile memory, you are then clear to interact with those bytes. Limiting, I know, but it is what it is.
The question asks for C#, but in Java one will have to setProperty as:
NativeLongByReference number = new NativeLongByReference( new NativeLong( EdSdkLibrary.EdsSaveTo.kEdsSaveTo_Host ) );
EdsVoid data = new EdsVoid( number.getPointer() );
NativeLong l = EDSDK.EdsSetPropertyData(edsCamera, new NativeLong(EdSdkLibrary.kEdsPropID_SaveTo), new NativeLong(0), new NativeLong(NativeLong.SIZE), data);
And the usual download will do

Categories

Resources