[英]openCv captureFromCam memory leak?
Here is part of the code i'm having a problem with, memory usage being tracked by memory_profiler 这是我遇到问题的部分代码,memory_profiler跟踪内存使用情况
27 48.500 MiB 0.000 MiB logging.debug("Initialize camera...")
29 63.996 MiB 15.496 MiB self.capture = cv.CaptureFromCAM(0)
30 78.102 MiB 14.105 MiB cv.SetCaptureProperty(self.capture,cv.CV_CAP_PROP_EXPOSURE,self.config.trackExposure)
31 59.551 MiB -18.551 MiB del self.capture
creating the capture object and configuring the properties uses 29.601 MiB of memory. 创建捕获对象并配置属性使用29.601 MiB的内存。
But, when I delete self.capture it only reclaims 18.551 MiB. 但是,当我删除self.capture时,它仅回收18.551 MiB。
Does it in cv2 as well... 在cv2中也是如此...
28 48.480 MiB 0.000 MiB logging.debug("Initialize camera...")
30 65.652 MiB 17.172 MiB self.capture = cv2.VideoCapture(0)
31 77.883 MiB 12.230 MiB self.capture.set(cv.CV_CAP_PROP_EXPOSURE,self.config.trackExposure)
32 59.332 MiB -18.551 MiB self.capture.release()
33 59.332 MiB 0.000 MiB del self.capture
Follow up - 跟进 -
Couldn't find an answer to my question, so for now my work around is to not release/delete the camera until the entire script quits. 找不到我的问题的答案,因此,现在我的解决方法是在整个脚本退出之前不要释放/删除相机。
There appears to be a "memory tax" where opencv wont release some memory every time you open and close a camera. 似乎有一种“内存税”,每次打开和关闭相机时,opencv都不会释放一些内存。
If the buffer appears to be lagging or holding old images when you come back to it, my fix has been to "clean" the cache manually... 如果您回到缓冲区时似乎缓冲区滞后或保留旧图像,则我的解决方法是手动“清理”缓存...
for x in range(3):
garbage = self.capture.QueryFrame()
It's not elegant but it gets the job done. 它不是很优雅,但是可以完成工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.