def __init__(self, *args, **kwargs): super(MainWindow, self).__init__(*args, **kwargs) self.setWindowTitle("Floc App") self.initUI() self.timer = QTimer(self) # timer.timeout.connect(self.take_photo) # timer.start(5000) # timer.start() width = self.width() height = self.height() self.setGeometry(10, 10, 900, 500) self.show() # database = r"C:sqlitedbpythonsqlite.db" # database = r"databse.db" sql_create_floc_table = """ CREATE TABLE IF NOT EXISTS flocs ( id integer PRIMARY KEY, size integer NOT NULL ); """ # create a database connection conn = database2.create_connection(database) conn.commit() # create tables if conn is not None: # create projects table database2.create_table(conn, sql_create_floc_table) else: print("Error! cannot create the database connection.")
def take_photo(self): self.viewfinder.setContrast(100) # self.viewfinder.setBrightness(0) timestamp = time.strftime("%d-%b-%Y-%H_%M_%S") path = (os.path.join( self.save_path, "%s-%04d-%s.jpg" % (self.current_camera_name, self.save_seq, timestamp))) img = self.capture.capture(path) # qimg = QImage() # qimg.load('image.jpg') # img = self.QImageToMat(self.capture) # database = r"C:\sqlite\db\pythonsqlite.db" # create a database connection conn = database2.create_connection(database) conn.commit() is_empty = True while is_empty: img = cv2.imread(path) if img is not None: is_empty = False # create tables if conn is not None: # create projects table cur = conn.cursor() database2.add_flocs(img, cur) conn.commit() conn.close() else: print("Error! cannot create the database connection.") self.save_seq += 1
def export(self): # create a database connection conn = database2.create_connection(database) conn.commit() # create tables if conn is not None: # create projects table database2.expToCSV(conn) else: print("Error! cannot create the database connection.")
import pandas as pd import matplotlib.pyplot as plt import database2 database = r"flocs.db" conn = database2.create_connection(database) curs = conn.cursor() sql = "SELECT datetime, SUM(size) AS Total_Size FROM flocs GROUP BY datetime" sqlsmall = "SELECT datetime, SUM(size) AS Small_Total_Size FROM flocs WHERE size < 1500 GROUP BY datetime" df = pd.read_sql(sql, conn) dfsmall = pd.read_sql(sqlsmall, conn) df = pd.merge(df, dfsmall, on='datetime') print(df['datetime'].str[11:]) plt.plot(df['datetime'].str[11:], df['Total_Size'], df['Small_Total_Size']) plt.xlabel("Time") plt.ylabel("Total Area of Flocs") plt.title("Total Area of Flocs (Blue) vs Area of Small Flocs (Orange)") plt.show()