I am trying to implement a image recognition program in C++.
I had completed the extracted of feature, now trying to save the large amount of numbers. I had 2 implementation in mind, one is to save the data into binary files, to reduce the overhead of computation, or I can use database to keep the information.
Binary file is fast to read and write, but hard to access, while database seem an easier interface to work with,开发者_StackOverflow社区 but I am not sure if the performance is fast enough.
Do you guys have any experience regarding fsream or database as the choice for fast persistent storage?
You could use SQLite. It basically gives to database-style access to local files. You can also create in-memory databases with it, but i do not know if it is possible to persist those.
Also, the best choice here heavily depends on your access patterns. If it is just sequenctial write and sequential read, then binary files are the best solution.
If you really want speed, consider using the C-style I/O functions such as fopen(0, fread() etc. These can often be notable faster than iostreams, for a number of reasons.
For me the advantage of using a database like SQLite is an independant format for my data and the ability to query the data using SQL.
Writing data to a SQLite database proved to be a lot slower than writing it to a simple CSV text file.
It depends what you want to do with the data afterwards? If you simply want to read it in again and do some stuff, use fstream (or C-style I/O) like suggested. If you want to query the data and only get specific data, use SQLite.
You also have to consider how you wish to store the data in a database. If you are going to store the data as a BLOB, you may end up losing the benefits of SQL and sacraficing performance.
I am writing an audio recognition program in C++, and I am using now PostgreSql for data storage. So I am interested in an answer too :). What I can propose is that, the data storage should be chosen according the recognition algorithm. If you compare your image with saved images 1 by 1, then binary files seem to be quicker. But if during recognition you work with several images at once, a database may be more speedy solution.
精彩评论