Page 1 of 2 12 LastLast
Results 1 to 20 of 25

Thread: Load in memory the content of a database

  1. #1
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Load in memory the content of a database

    Good morning,
    I'm developing a biometric system based on iris recognition and the templates of every user are stored in a database. Unfortunately I have no experience with databases.
    I would know if is there a way to read in memory the content of the database in 1 shot ( it's possible in VB IIRC ) intead of looping on every database entry.
    For example in my case every entry has 4 fields:

    1. user id - QString
    2. iris code 1 - uchar array[1560]
    3. iris code 2 - uchar array[1560]
    4. iris code 3 - uchar array[1560]

    This because if there are too much entries in the database it can take long time to loop on every one.

    Best Regards,
    Franco
    Franco Amato

  2. #2
    Join Date
    Jul 2009
    Posts
    74
    Thanks
    2
    Thanked 6 Times in 6 Posts

    Default Re: Load in memory the content of a database

    your request is annoying...

    > I'm developing a biometric system based on iris recognition
    impressive !
    >I have no experience with databases.
    just read 10 minutes of documentation... you dont need more !

    you should use QSQLITE (sqlite)
    (search in qt assistant for "SQL Database drivers")
    You can have that kind of database in memory:
    SQLite also supports in-memory databases, simply pass ":memory:" as the database name.

  3. #3
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Load in memory the content of a database

    You really should read some documentation before continuing.

    Using a database to store all the information and then ignoring all the benefits of that database and doing all the work yourself (such as searching for specific data) is just nuts. As is looping on every database entry. Design your database schema first before doing a single line of coding. Decide how it will all work. If you don't, I'll only come back to bite you later on.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Load in memory the content of a database

    How do you need to query the database? Are you looking for an entry by userid or are you trying to find the entry that matches an iris scan (i.e. searching in the binary blobs)? The first option is trivial and any RDBMS will do this with little to no effort on your part (certainly no programatic iteration over the whole data set). The second option may be more difficult.

  5. #5
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Load in memory the content of a database

    Quote Originally Posted by ChrisW67 View Post
    How do you need to query the database? Are you looking for an entry by userid or are you trying to find the entry that matches an iris scan (i.e. searching in the binary blobs)? The first option is trivial and any RDBMS will do this with little to no effort on your part (certainly no programatic iteration over the whole data set). The second option may be more difficult.
    Hi Chris,
    Is the second option. I need to scan every iris_code ( 3 per user ) and perform a matching. I thought to load all iris codes in memory and doing the process in memory but maybe I'm wrong.
    I have zero experience with databases.
    Best Regards,
    Franco
    Franco Amato

  6. #6
    Join Date
    Dec 2010
    Location
    US, Washington State
    Posts
    54
    Thanks
    3
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Load in memory the content of a database

    Quote Originally Posted by franco.amato View Post
    Good morning,
    I'm developing a biometric system based on iris recognition and the templates of every user are stored in a database.
    Is there an upper limit to the number of stored templates? If all the templates are in memory, how long do you guess a query would take?

  7. #7
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Load in memory the content of a database

    Quote Originally Posted by pkohut View Post
    Is there an upper limit to the number of stored templates? If all the templates are in memory, how long do you guess a query would take?
    Hi no,
    there is not an upper limit.
    Franco Amato

  8. #8
    Join Date
    Dec 2010
    Location
    US, Washington State
    Posts
    54
    Thanks
    3
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Load in memory the content of a database

    Get a database management tool for your database system. Using it you can form queries to the database in an interactive way. Once you discover what queries need to be made to get the results you want then translate those queries to your application. If you're database is SQL Server based then MS has the free "Microsoft SQL Server Management Studio Express", get the version that matches your server (2005, 2008).

    What database system do you use? Someone here can probably point you to a good management tool for your particular system.
    http://en.wikipedia.org/wiki/Compari...database_tools

  9. #9
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Load in memory the content of a database

    Quote Originally Posted by pkohut View Post
    Get a database management tool for your database system. Using it you can form queries to the database in an interactive way. Once you discover what queries need to be made to get the results you want then translate those queries to your application. If you're database is SQL Server based then MS has the free "Microsoft SQL Server Management Studio Express", get the version that matches your server (2005, 2008).

    What database system do you use? Someone here can probably point you to a good management tool for your particular system.
    http://en.wikipedia.org/wiki/Compari...database_tools
    Hi,
    I already know which query I have to do and this was not my initial question.
    Regards,
    Franco
    Franco Amato

  10. #10
    Join Date
    Dec 2010
    Location
    US, Washington State
    Posts
    54
    Thanks
    3
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Load in memory the content of a database

    Quote Originally Posted by franco.amato View Post
    Hi,
    I already know which query I have to do and this was not my initial question.
    Regards,
    Franco
    If there is no upper limit to the number of database entries, then "to read in memory the content of the database in 1 shot" is not a solution. It's possible that the current query can be reformed to work more efficient with the db. Playing what if queries in an interactive way can help with the discovery.

    I don't know what your query is or the db structure. From the description it sounds like the query is doing a brute force search. If so, then maybe this simple, far from optimized, approach could be better than the current one. There are iris codes 1 - 3, lets call them x, y, z.
    1) get collection results of everything matching x.
    2) from previous result set, get collection result of everything matching y.
    3) from previous result set, get collection result of everything matching z.
    4) Should have 1 result in collection.

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Load in memory the content of a database

    Quote Originally Posted by franco.amato View Post
    Hi Chris,
    Is the second option. I need to scan every iris_code ( 3 per user ) and perform a matching. I thought to load all iris codes in memory and doing the process in memory but maybe I'm wrong.
    I have zero experience with databases.
    To be honest such things are not done like that. This is a special case of image classification and if you want to do it fast you should use an algorithm dedicated for it. While searching three scans for ten people is not a big effort, when your database grows, the complexity of the problem grows in a non-linear manner. So basically you should either "pre-teach" your system with a static set of images (for example using neural networks) which then reduces the classification complexity practically to O(1) or use some other kind of clustering & classification heuristics to match the scans. Especially that you will never get two identical scans of the same iris due to changing environmental conditions (such as ambient light) so you will have to work on "features" and not pixel by pixel comparison anyway. I don't see how a database is helpful in any of this unless the matching algorithm is implemented as a stored procedure for it (then it's just a matter of performing a single SELECT query to find the id of the person matching the scan).

    As for what you wrote about VB - the fact that you need one line of code in your program to load all records from the database to memory doesn't mean that internally the engine is not looping over records. So if you write one line of code or four lines of code it doesn't matter as internally the same operation is performed so the one line version is not "faster" than the four line version.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. #12
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Load in memory the content of a database

    Here is an example that creates an Sqlite database with 100 test rows and a series of queries against it.
    Qt Code:
    1. #include <QtCore>
    2. #include <QtSql>
    3. #include <QDebug>
    4.  
    5. void createTestData()
    6. {
    7. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    8. db.setDatabaseName("test.db");
    9. if (db.open()) {
    10.  
    11. QSqlQuery query;
    12. query.exec("create table irisdata ("
    13. "userid varchar(20), "
    14. "iriscode1 blob, "
    15. "iriscode2 blob, "
    16. "iriscode3 blob, "
    17. "primary key(userid) )");
    18. if (query.prepare( "insert into irisdata ("
    19. "userid, iriscode1, iriscode2, iriscode3) "
    20. "values (?, ?, ?, ?)" )) {
    21. for (int i=0; i<100; ++i) {
    22. QByteArray blobData1(i+1, 'a');
    23. QByteArray blobData2(i+1, 'b');
    24. QByteArray blobData3(i+1, 0x83);
    25. query.bindValue(0, QString("User %1").arg(i));
    26. query.bindValue(1, blobData1);
    27. query.bindValue(2, blobData2);
    28. query.bindValue(3, blobData3);
    29. query.exec();
    30. }
    31. }
    32. }
    33. }
    34.  
    35. void queryTestData(const QByteArray &ba)
    36. {
    37. QSqlDatabase db = QSqlDatabase::database();
    38. QSqlQuery query;
    39. if (query.prepare(
    40. "select userid from irisdata "
    41. "where iriscode1 = ? OR iriscode2 = ? or iriscode3 = ?") ) {
    42. query.bindValue(0, ba);
    43. query.bindValue(1, ba);
    44. query.bindValue(2, ba);
    45. if (query.exec()) {
    46. while (query.next())
    47. qDebug() << "Found" << query.value(0).toString();
    48. }
    49. }
    50. }
    51.  
    52. int main(int argc, char *argv[])
    53. {
    54. QCoreApplication app(argc, argv);
    55.  
    56. createTestData();
    57. queryTestData(QByteArray(3, 'a')); // user 2
    58. queryTestData(QByteArray(5, 'b')); // user 4
    59. queryTestData(QByteArray(10, 0x83)); // user 9
    60. queryTestData(QByteArray(10, 0x00)); // does not exist
    61. }
    To copy to clipboard, switch view to plain text mode 
    Should work against a Mysql or other database also.

  13. #13
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Load in memory the content of a database

    This because if there are too much entries in the database it can take long time to loop on every one.
    I have no experience with databases
    If you don't know anything about databases, how do you know if the one you're using is too slow in this case?

    More to the point: why are you trying to code a particular solution if you know nothing about how to implement the solution you've chosen?

  14. #14
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Load in memory the content of a database

    Quote Originally Posted by wysota View Post
    To be honest such things are not done like that. This is a special case of image classification and if you want to do it fast you should use an algorithm dedicated for it. While searching three scans for ten people is not a big effort, when your database grows, the complexity of the problem grows in a non-linear manner. So basically you should either "pre-teach" your system with a static set of images (for example using neural networks) which then reduces the classification complexity practically to O(1) or use some other kind of clustering & classification heuristics to match the scans. Especially that you will never get two identical scans of the same iris due to changing environmental conditions (such as ambient light) so you will have to work on "features" and not pixel by pixel comparison anyway. I don't see how a database is helpful in any of this unless the matching algorithm is implemented as a stored procedure for it (then it's just a matter of performing a single SELECT query to find the id of the person matching the scan).

    As for what you wrote about VB - the fact that you need one line of code in your program to load all records from the database to memory doesn't mean that internally the engine is not looping over records. So if you write one line of code or four lines of code it doesn't matter as internally the same operation is performed so the one line version is not "faster" than the four line version.
    Hi Wysota.
    I don't know how a neural network can help me. IN the database I don't store iris images but only the extracted encoded iris code.
    Regards,

    Quote Originally Posted by SixDegrees View Post
    If you don't know anything about databases, how do you know if the one you're using is too slow in this case?

    More to the point: why are you trying to code a particular solution if you know nothing about how to implement the solution you've chosen?
    SixDegrees I was part of the development of the iris recognition kernel and now I would implement a demo showing the results of the matching.
    So my 'problem' is looping through the iris codes stored in the database.
    Regards


    Added after 10 minutes:


    Quote Originally Posted by ChrisW67 View Post
    Here is an example that creates an Sqlite database with 100 test rows and a series of queries against it.
    Qt Code:
    1. #include <QtCore>
    2. #include <QtSql>
    3. #include <QDebug>
    4.  
    5. void createTestData()
    6. {
    7. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    8. db.setDatabaseName("test.db");
    9. if (db.open()) {
    10.  
    11. QSqlQuery query;
    12. query.exec("create table irisdata ("
    13. "userid varchar(20), "
    14. "iriscode1 blob, "
    15. "iriscode2 blob, "
    16. "iriscode3 blob, "
    17. "primary key(userid) )");
    18. if (query.prepare( "insert into irisdata ("
    19. "userid, iriscode1, iriscode2, iriscode3) "
    20. "values (?, ?, ?, ?)" )) {
    21. for (int i=0; i<100; ++i) {
    22. QByteArray blobData1(i+1, 'a');
    23. QByteArray blobData2(i+1, 'b');
    24. QByteArray blobData3(i+1, 0x83);
    25. query.bindValue(0, QString("User %1").arg(i));
    26. query.bindValue(1, blobData1);
    27. query.bindValue(2, blobData2);
    28. query.bindValue(3, blobData3);
    29. query.exec();
    30. }
    31. }
    32. }
    33. }
    34.  
    35. void queryTestData(const QByteArray &ba)
    36. {
    37. QSqlDatabase db = QSqlDatabase::database();
    38. QSqlQuery query;
    39. if (query.prepare(
    40. "select userid from irisdata "
    41. "where iriscode1 = ? OR iriscode2 = ? or iriscode3 = ?") ) {
    42. query.bindValue(0, ba);
    43. query.bindValue(1, ba);
    44. query.bindValue(2, ba);
    45. if (query.exec()) {
    46. while (query.next())
    47. qDebug() << "Found" << query.value(0).toString();
    48. }
    49. }
    50. }
    51.  
    52. int main(int argc, char *argv[])
    53. {
    54. QCoreApplication app(argc, argv);
    55.  
    56. createTestData();
    57. queryTestData(QByteArray(3, 'a')); // user 2
    58. queryTestData(QByteArray(5, 'b')); // user 4
    59. queryTestData(QByteArray(10, 0x83)); // user 9
    60. queryTestData(QByteArray(10, 0x00)); // does not exist
    61. }
    To copy to clipboard, switch view to plain text mode 
    Should work against a Mysql or other database also.
    Hi Chris,
    your code is very interesting but the 'queryTestData' will not work because a iris code will never be the same. A matching is performed calculating the hamming distance over 2 iris codes. Something like this:
    Qt Code:
    1. if ( hamming_distance( iris_code1, iris_code2) < threshold )
    2. qDebug() << " MATCH ";
    3. else
    4. qDebug() << " NO MATCH ";
    To copy to clipboard, switch view to plain text mode 

    So I think it's mandatory to scan every code stored in the database.

    Best Regards
    Last edited by franco.amato; 31st December 2010 at 06:47.
    Franco Amato

  15. #15
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Load in memory the content of a database

    Are you calculating the hamming distance between the values in two columns of the same record, or between a candidate iris code and each of three columns in each record? If it is the former then you only ever need do this once and store the result.

    Have you profiled your code to make sure that it is not the hamming distance algorithm that is chewing the time? Don't waste time optimising something that is not the biggest problem.

    It is possible to provide an extension to Sqlite to give it the hamming_distance function it does not currently have. This is will be more efficient than dragging the data through Qt's Sql layers but is obviously another bunch of APIs to learn.

  16. #16
    Join Date
    Dec 2010
    Location
    US, Washington State
    Posts
    54
    Thanks
    3
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Load in memory the content of a database

    Quote Originally Posted by franco.amato View Post
    Hi Wysota.
    I don't know how a neural network can help me. IN the database I don't store iris images but only the extracted encoded iris code.
    Regards,

    SixDegrees I was part of the development of the iris recognition kernel and now I would implement a demo showing the results of the matching.
    So my 'problem' is looping through the iris codes stored in the database.
    Regards

    Hi Chris,
    your code is very interesting but the 'queryTestData' will not work because a iris code will never be the same. A matching is performed calculating the hamming distance over 2 iris codes. Something like this:
    Qt Code:
    1. if ( hamming_distance( iris_code1, iris_code2) < threshold )
    2. qDebug() << " MATCH ";
    3. else
    4. qDebug() << " NO MATCH ";
    To copy to clipboard, switch view to plain text mode 

    So I think it's mandatory to scan every code stored in the database.

    Best Regards
    Based on the information you've provided I'd look into storing a spatial index in the database. Queries could then be very fast. This link might be of use (refer to the excepted answer).
    http://stackoverflow.com/questions/3...mysql-database

    Given the luxury of having a whole spatial index in memory, look into adapting the Kd-tree algorithm to the data set. Iris codes 1 - 3 are treated as X, Y, Z coordinates, distance calculations would use the hammering algorithm. Then nearest neighbor and nearest range queries could be performed.

  17. #17
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Load in memory the content of a database

    Quote Originally Posted by franco.amato View Post
    I don't know how a neural network can help me. IN the database I don't store iris images but only the extracted encoded iris code.
    Based on the features (the "iris code" as you call it) it immediately classifies an unknown feature vector into a pre-learned set of feature sets (iris scans) without the need for looping over each iris record and performing the comparison. Then you don't even have to load the scans from the database or just load one or two to confirm the results of the algorithm.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  18. #18
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Load in memory the content of a database

    Quote Originally Posted by ChrisW67 View Post
    Are you calculating the hamming distance between the values in two columns of the same record, or between a candidate iris code and each of three columns in each record?
    It's between a candidate and each of the three columns in each record.

    If it is the former then you only ever need do this once and store the result.
    I didn't get you.

    Have you profiled your code to make sure that it is not the hamming distance algorithm that is chewing the time? Don't waste time optimising something that is not the biggest problem.
    The matching routine is really fast.
    My initial doubt was if I have to copy all database entry in memory and performing the matching there instead of doing n queries against the database.

    It is possible to provide an extension to Sqlite to give it the hamming_distance function it does not currently have. This is will be more efficient than dragging the data through Qt's Sql layers but is obviously another bunch of APIs to learn.
    Here we're using microsoft sql express 2005.
    Regards
    Franco Amato

  19. #19
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Load in memory the content of a database

    Quote Originally Posted by franco.amato View Post
    Here we're using microsoft sql express 2005.
    I'm sure it can be extended with custom functions as well.

    The first three links from Google:
    http://www.sqlteam.com/article/user-defined-functions
    http://www.sqlteam.com/article/intro...ctions-updated
    http://www.dreamincode.net/forums/to...ions-in-mssql/
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  20. #20
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Load in memory the content of a database

    Quote Originally Posted by wysota View Post
    Thank you very much Wysota, my head is exploting these days trying to find a solution.
    Best Regards
    Franco Amato

Similar Threads

  1. how to load images from phone memory
    By trupti in forum Qt Programming
    Replies: 11
    Last Post: 7th January 2011, 11:24
  2. QSqlite, multiple connections to in memory database.
    By adzajac in forum Qt Programming
    Replies: 9
    Last Post: 10th March 2010, 22:35
  3. inserting content in database
    By codeman in forum Qt Programming
    Replies: 2
    Last Post: 3rd June 2009, 16:47
  4. Load textfile content into a textEdit
    By gt.beta2 in forum Newbie
    Replies: 1
    Last Post: 3rd March 2009, 22:57
  5. Load menu from database
    By daica2003 in forum Qt Programming
    Replies: 5
    Last Post: 11th May 2008, 18:18

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.