存储 100,000 个的好方法是什么?整数(代表图像增量数据)?
我搜索了论坛并看到了这个问题的一些可能的部分解决方案,但我希望有人帮助将它们放在一起。
我从相机获取帧并对当前帧和前一帧之间的差异进行图像处理。除了来自相机的 RGB 值之外,我还计算每个像素的色相和饱和度,每个像素也是一个 int。所以我的两个问题是:
存储每次调用
didOutputSampleBuffer
时的所有这些值的最佳方法是什么?从我读到的内容来看,似乎有这么多值, NSNumber 的开销将是显而易见的,因此使用经典的 C 风格整数数组(长度为 144 x 192 x 5(R,G ,B,H,S) = 138,240。这有意义吗?如何将此数组放入 didOutputSampleBuffer 方法的范围内,因为我是在应用程序启动时初始化该数组,而不是在 didOutputSampleBuffer 方法中初始化该数组。论坛上有人提到也许我可以将数组包装在 NSMutableData 中,然后我可以将其存储为属性?
谢谢你的建议, 大学教师
I've searched the forum and seen some possible partial solutions to this question, but I'd like help putting it all together.
I'm getting the frames from the camera and doing image processing on the difference between the current frame and previous frame. In addition to the RGB values from the camera, I'm also calculating Hue and Saturation for each pixel, each of which is also an int. So my 2 questions are:
What is the best way to store all of these values from each call to
didOutputSampleBuffer
? From what I've been reading, it seems like with this many values, the overhead from NSNumber will be noticable so least memory would be spent using a classic c-style array of ints w/ length 144 x 192 x 5(R,G,B,H,S) = 138,240. Does that make sense?How do I put this array in the scope of my didOutputSampleBuffer method, because I'm initializing the array upon app launch, not in the didOutputSampleBuffer method. Someone on the forum mentioned perhaps I could wrap the array in NSMutableData and then i could just store it as a property?
Thank you for your advice,
Don
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
鉴于图像的大小不会改变,您应该能够创建一个缓冲区来将这些组件存储为交错字节或每个颜色组件平面的几个缓冲区。您可以通过手动使用
malloc()
和free()
创建此缓冲区并在完成后销毁它来完成此操作。如果您更喜欢使用引用计数,您可以将这些字节包装在 NSData 实例中,这不会给您的处理增加太多开销。指向已处理缓冲区字节的指针或 NSData 实例都可以用作属性。
请注意,您可能希望为每个组件使用
unsigned char
类型,因为您只为每个颜色组件获取单独的字节。为什么要以不必要的精度浪费内存?Given that the size of an image won't change, you should be able to create a buffer to store these components as interleaved bytes or a few buffers for each color component plane. You could do this by manually using
malloc()
andfree()
to create this buffer and destroy it when done.If you'd prefer to use reference counting, you could wrap these bytes in an NSData instance, which won't add much overhead to your processing. Either a pointer to your processed buffer bytes or an NSData instance could be used as properties.
Note that you'll probably want to use
unsigned char
types for each component, because you're only getting back individual bytes for each of the color components. Why waste memory with unnecessary precision?例子:
Example:
当我处理类似的问题时,我只是将 c 样式数组设置为对象上的 ivar。
这样我就可以向它附加附加属性,例如元数据等。
在这种情况下,您仍然必须显式管理内存。
When I was dealing with a similar problem I simply made the c style array an ivar on an object.
This way I could attach additional properties to it like metadata, etc.
You still have to explicitly manage the memory in this case.