Comments (13)
Hello.
I think my library do not have problem of leaking memory.
- library include 2 sample project, 'UsbCameraForms' and 'UsbCameraWpf'. Use these sample projects and let me know crash happens or not.
- if possible, show me your code.
- tell me product name of external video capture card.
from usbcamera.
Im aslo facing the same issue. GC is not collecting. Memory keeps on increasing when it reaches 3.9 GB it ends in Out of memory exception. My camera is See3CAM_CU55 by eCam and its details are 5 MP (2592 x 1944) 24 fps and 12 fps Uncompressed
UYVY and Compressed MJPEG 60 fps .
from usbcamera.
Im aslo facing the same issue. GC is not collecting. Memory keeps on increasing when it reaches 3.9 GB it ends in Out of memory exception. My camera is See3CAM_CU55 by eCam and its details are 5 MP (2592 x 1944) 24 fps and 12 fps Uncompressed UYVY and Compressed MJPEG 60 fps .
![]()
change
var timer = new System.Timers.Timer(1000 / 30) { SynchronizingObject = this };
timer.Elapsed += (s, ev) => pictureBox1.Image = camera.GetBitmap();
timer.start();
to
var timer = new System.Timers.Timer(1000 / 30) { SynchronizingObject = this };
timer.Elapsed += (s, ev) =>
{
var oldImage = pictureBox1.Image;
pictureBox1.Image = camera.GetBitmap();
if(oldImage!=null)
{
oldImage.Dispose();
}
};
timer.start();
from usbcamera.
from usbcamera.
改用其他库,该库存在明显的内存回收问题,起因是外接的usb设备无法管理
并没有问题哦 我有项目跑了2年了 前台登记的客户端 一点内存都没漏
只是例子里 没释放pictureBox1.Image旧图片
你用啥库 只要是把图片clone一份到pictureBox1.Image 都得自己释放
from usbcamera.
from usbcamera.
您的库在系统自带的摄像头下无任何问题,一旦有其他的外接采集卡存在,内存即使自己回收,也还是会有问题
…
---Original--- From: @.> Date: Thu, Oct 12, 2023 19:47 PM To: @.>; Cc: @.@.>; Subject: Re: [secile/UsbCamera] Memory issues (Issue #27) 改用其他库,该库存在明显的内存回收问题,起因是外接的usb设备无法管理 并没有问题哦 我有项目跑了2年了 前台登记的客户端 一点内存都没漏 只是例子里 没释放pictureBox1.Image旧图片 你用啥库 只要是把图片clone一份到pictureBox1.Image 都得自己释放 — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>
你得翻译成英文啊 作者看不懂中文
然后 USB摄像头我跑了很久没问题
采集卡的话 我没有 不知道什么情况
现在的项目都要考虑信创 不用这个库了
from usbcamera.
Tried your change still it leads to out of memory error. Only one time GC is calling atr 3.5 GB. then it leads to out of memory exception. When I changed this function
public int BufferCB(double SampleTime, IntPtr pBuffer, int BufferLen)
{
if (Buffer == null || Buffer.Length != BufferLen)
{
Buffer = new byte[BufferLen];
}
// replace lock statement to Monitor.TryEnter. (issue #14)
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);
Buffer = null;
}
// notify buffered to worker thread. (issue #16)
if (Buffered != null) BufferedEvent.Set();
return 0;
}
To this
public int BufferCB(double SampleTime, IntPtr pBuffer, int BufferLen)
{
byte[] tempBuffer = new byte[BufferLen];
var locked = false;
try
{
System.Threading.Monitor.TryEnter(BufferLock, 0, ref locked);
if (locked)
{
Marshal.Copy(pBuffer, tempBuffer, 0, BufferLen);
//Console.WriteLine("BufferLen " + BufferLen);
Buffer = tempBuffer;
tempBuffer = null;
}
}
finally
{
if (locked) System.Threading.Monitor.Exit(BufferLock);
}
// notify buffered to worker thread. (issue #16)
if (Buffered != null) BufferedEvent.Set();
return 0;
}
GC is calling very frequently. But it is not leading to Out of memory exception. Any idea what is happening ?
from usbcamera.
@SankarGaneshKumar maybe you can try FlashCap
It can run on Linux and Windows
if you want run on mac you can try kekyo/FlashCap#65
from usbcamera.
hello, SankarGaneshKumar.
sorry, I do not have time, so in short.
I have ever experienced this problem once.
At that time, when I changed target framework .NET Framework version, the problem is disapeared.
Could you try?
from usbcamera.
from usbcamera.
If it doesn't work, there's one more thing you can try.
Recently, I added 'USBCAMERA_BYTEARRAY' symbol.
if 'USBCAMERA_BYTEARRAY' symbol defined, GetBitmap() returns image data as byte array.
Define 'USBCAMERA_BYTEARRAY' symbol and try the code below.
// 2. use Timer and GetBitmap().
var timer = new System.Timers.Timer(1000 / 30) { SynchronizingObject = this };
timer.Elapsed += (s, ev) =>
{
var buf = (byte[])camera.GetBitmap();
pictureBox1.Image = BufferToBitmap(buf, camera.Size.Width, camera.Size.Height);
};
timer.Start();
private static Bitmap BufferToBitmap(byte[] buffer, int width, int height)
{
var result = new Bitmap(width, height);
var bmpData = result.LockBits(new Rectangle(Point.Empty, result.Size), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
System.Runtime.InteropServices.Marshal.Copy(buffer, 0, bmpData.Scan0, buffer.Length);
result.UnlockBits(bmpData);
return result;
}
from usbcamera.
I would like to summarize what we currently know about this issue.
- If you use a timer (or subscribe PreviewCaptured) instead of SetPreviewControl, an error may occur.
- in my environment, when VideoFormat image size is greater that 1920×1080, error happens.
- when VideoFormat image size is smaller than 1280×1024, error not happen.
- It is thought that the reason why error happen is out of memory due to Bitmap not being disposed.
- I previously said 'changed target framework .NET Framework version, the problem is disapeared', but maybe this is not correct.
- I previously said ''define USBCAMERA_BYTEARRAY' symbol', this has an effect.
- the reason may that creating new Bitmap in local function make bitmap GC generation to 0, therefor, bitmap is disposed aggressively.
Basically, bitmap object is disposed automatically by GC, so it is not occur out of memory error in normal situation.
But for various reasons, for example, selecting large image size, bitmap is not disposed collectly and error occur.
If you are in the situation, you have to dispose bitmap expressly.
Please see also issue34.
I'll remain this issue open for a while.
If the same problem is not reported after a while, I will close this issue.
from usbcamera.
Related Issues (20)
- How can I get the datas of every frame? HOT 9
- missing events HOT 4
- How can I switch camera? HOT 2
- provide nuget package HOT 4
- Implement IDisposable / IObservable pattern HOT 1
- 需要增加对于部分非标的虚拟摄像头的过滤(It is necessary to increase the filtering of some non-standard virtual cameras) HOT 7
- Problem with showing preview HOT 4
- How to distinguish the camera with the same name? HOT 4
- Add a feature to get plain image data as byte array to not call lock bits over and over again HOT 15
- threads in thread pool may be blocked by this library HOT 4
- Inconsistent Image Quality When Saving Still Capture Monochrome Sensor Data as BMP HOT 8
- Can't able to set brightness and exposure at run time when camera running on different thread HOT 2
- Capture Pin not working on all cameras HOT 3
- happens ArgumentException when I dispose PictureBox's old image. HOT 1
- How can I turn off the usbcamera lights? HOT 9
- why not working in 4K? HOT 6
- Add an IsReady method to see if we can get the image? HOT 3
- Can't creat filter error when running on a different windows machine than what I developed on. HOT 1
- Why my computer has released resources before sleep, wake up and then open the camera will be stuck.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from usbcamera.