-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Camera preview locked #13
Comments
Hello, Thank you for your question.
before change. public int BufferCB(double SampleTime, IntPtr pBuffer, int BufferLen)
{
if (Buffer == null || Buffer.Length != BufferLen)
{
Buffer = new byte[BufferLen];
}
lock (BufferLock)
{
Marshal.Copy(pBuffer, Buffer, 0, BufferLen);
}
return 0;
} after change. public int BufferCB(double SampleTime, IntPtr pBuffer, int BufferLen)
{
lock (BufferLock)
{
if (Buffer == null || Buffer.Length != BufferLen)
{
Buffer = new byte[BufferLen];
}
Marshal.Copy(pBuffer, Buffer, 0, BufferLen);
}
return 0;
} |
Thanks for your suggestion, I modified the code as shown. The defect seems less frequent, moreover it does it especially when the camera is cold and it happens also with AMCAP. With their test program IC Capture (The Imagin Source) it never happens. |
Hello.
before change: GetBitmap(int width, int height, int stride)
{
if (Buffer == null) return EmptyBitmap(width, height);
lock (BufferLock)
{
return BufferToBitmap(Buffer, width, height, stride);
}
} after change: GetBitmap(int width, int height, int stride)
{
lock (BufferLock)
{
if (Buffer == null) return EmptyBitmap(width, height);
return BufferToBitmap(Buffer, width, height, stride);
}
}
// check format.
int cameraIndex = 0;
UsbCamera.VideoFormat[] formats = UsbCamera.GetVideoFormat(cameraIndex);
for(int i=0; i<formats.Length; i++) Console.WriteLine("{0}:{1}", i, formats[i]); |
Hello. This is previous version document, it is prohibited to enter critical section. Could you try this version? public int BufferCB(double SampleTime, IntPtr pBuffer, int BufferLen)
{
if (Buffer == null || Buffer.Length != BufferLen)
{
Buffer = new byte[BufferLen];
}
var locked = false;
try
{
System.Threading.Monitor.TryEnter(BufferLock, 0, ref locked);
if (locked)
{
Marshal.Copy(pBuffer, Buffer, 0, BufferLen);
}
}
finally
{
if (locked) System.Threading.Monitor.Exit(BufferLock);
}
return 0;
} |
Hello, I modified as follows: public int BufferCB(double SampleTime, IntPtr pBuffer, int BufferLen)
} But the image freeze with the cold board continues; then the board warms up and does not freeze anymore. I immediately thought of a hardware problem since it freezes with the old AMCAP; but as I told you this problem never happens with their (the Imaging Source) IC Capture 2.5 program. Anyway I bought a new camera-board that will arrive next month.For the moment I put a 200 ms timer that compares the previous frame with the next one (I reduce the frames to 1/16 to speed up), when they are identical (normally there is always some flickering) I give the commands Camera.Stop(), Camera.Start(). But it's not very nice. |
AMCAP, as UsbCamera is based on DirectShow, while IC Capture is a software based on IC Imaging Control .NET Component for C# and VB.NET projects. |
I also tried an old version of UsbCamera where there was no callback function but there was GetBitmapMain and GetBitmapMainMain, but even with that same problem. Waiting for the new camera-board to arrive to draw conclusions. |
Thank you for your response. One last thing I want to check. // check format.
int cameraIndex = 0;
UsbCamera.VideoFormat[] formats = UsbCamera.GetVideoFormat(cameraIndex);
for(int i=0; i<formats.Length; i++) Console.WriteLine("{0}:{1}", i, formats[i]); for example, this is my result.
Now, if you are using formats[0], (that is [MJPG]), var camera = new UsbCamera(0, formats[0]); please use same size but another format like formats[9] (that is [YUY2]) or formats[18] (that is [RGB24])? |
I use format #5 |
The camera is black and white, that's why I had chosen the Y800 1280x960 format. Now however, after setting the RGB24 1280x960 format it seems that the defect does not. I need to try longer, but it already seems significant. |
I have one question. When you used format #5 (Y800), aside from occasional preview freeze, are you able to get correct image? (unbroken image?) BufferToBitmap function works correctly if image memory layout is RGB24. But you are using Y800 format and it's memory layout is difference from RGB24. |
Hi, |
Thank you. I'm feeling little strangeness, but I accept the result. I close this issue. If you have any question, ask me again, but I have not so much idea any more. |
Using a The Imaging Source USB 3.1 1440 x 1080 px camera sometimes, especially at the beginning, the preview freezes and you have to do Camera.Stop() + Camera.Start() to make it restart. What could it be?
The text was updated successfully, but these errors were encountered: