Home > front end >  Could not open database file Reason: file is not a databse, in DB browser and python
Could not open database file Reason: file is not a databse, in DB browser and python

Time:11-10

I am trying to do pedestrian detection for which I need to train my SVM for which I am loading the Diamler dataset(link), While loading it in python it shows the same error as DB browser which is "Could not open database file Reason: file is not a database". While the file easily opened in internet explorer. Database download link - link

My python code is :

import sqlite3
con = sqlite3.connect('GroundTruth2D.db')
cur = con.cursor()

cur.execute("SELECT * FROM sqlite_master")
records = cur.fetchall()
print("Total rows in table - ",cur.rowcount)

print(records)

While DB browser I am using is here

CodePudding user response:

The link you provided has a .tar.gz extension, but when downloaded is not actually a .tar.gz file but just a basic .tar. Rename the file to .tar to be able to access it as intended.

The .tar appears to contain Matlab scripts and the database that is accessed by them, but they don't appear to be sqlite3 databases, so you can't just open them with sqlite3.

You need to either find a Python package able to read this database format, or convert the data using Matlab and store it as a SQLite database to access it the way you planned.

CodePudding user response:

So they have kept file extenion as .db but it is infact a .txt file type where we have to read everyline and extract data using parser.

python code for parsing data:

import readSequence
seq_separator =":"
img_separator = ";"
obj_2d_separator = "#"

seqcount = -1
imgcount = -1
objcount = 0

seqs = []

f = open("GroundTruth2D.db", "r")

line = f.readline()
line = line.strip()
while line:
    if line==":":
        seq_id = f.readline().strip()
        path_to_data = f.readline().strip()
        numimages = f.readline().strip()
        seq = readSequence.readSequences(seq_id, path_to_data, numimages)
        seqs.append(seq)
        seqcount =1
    elif line==";":
        imgcount =1
        nameimg = f.readline().strip()
        [width,height] = f.readline().strip().split(" ")
        numobj = f.readline().strip().split(" ")[1]
        seqs[seqcount].addimage(nameimg, width, height, numobj)
    elif line[0] =="#":
        objclass = line[2:].strip()
        objid = f.readline().strip()
        conf = f.readline().strip()
        [min_x,min_y,max_x,max_y] = f.readline().strip().split(" ")
        seqs[seqcount].addobj(objclass, objid, conf, [min_x,min_y, max_x,max_y])
    line = f.readline()
    line=line.strip()

readSequence.py->

class read2Dobj:
    def __init__(self, objclass = None, objid=None, conf=None, coord=None):
        self.objclass = objclass
        self.objid = objid
        self.conf = conf
        self.coord = coord
    def setobjclass(self, objclass):
        self.objclass = objclass
    def setobjid(self, objid):
        self.objid = objid
    def setconf(self,conf):
        self.conf = conf
    def setcoord(self, coord):
        self.coord = coord
class readImage:
    count = 0
    def __init__(self,name=None, width=None, height=None, numobj=None):
        self.name = name
        self.width = width
        self.height = height
        self.numobj = numobj
    def setname(self,name):
        self.name = name
    def setwidth(self,width):
        self.width = width
    def setheight(self,height):
        self.height = height
    def setnumobj(self,numobj):
        self.numobj = numobj
        self.objs = [read2Dobj() for i in numobj]
    def addobjs(self, objclass=None, objid=None, conf=None, coord=None):
        self.objs[self.count].setobjclass(objclass)
        self.objs[self.count].setobjid(objid)
        self.objs[self.count].setconf(conf)
        self.objs[self.count].setcoord(coord)
        self.count =1
class readSequences:
    count = 0
    def __init__(self, seq_id, path_to_data, numimages):
        self.seq_id = seq_id
        self.path_to_data = path_to_data
        self.numimages = numimages
        self.imgs = [readImage() for i in range(int(self.numimages))]
    def addimage(self, name, width, height, numobj):
        self.imgs[self.count].setname(name)
        self.imgs[self.count].setwidth(width)
        self.imgs[self.count].setheight(height)
        self.imgs[self.count].setnumobj(numobj)
        self.count =1
    def addobj(self, objclass=None, objid=None, conf=None, coord=None):
        self.imgs[self.count-1].addobjs(objclass, objid,conf,coord)
  • Related