Example #1
0
 def __init__(self, run_id, folder, writeImages = False):
     self.run_id = run_id
     self.folder = folder
     self.writeImages = writeImages
     self.newPartCounter = 1
     self.count = 1
     self.x_last = None
     self.y_last = None
     self.w_last = None
     self.h_last = None
     self.ts_last = None
     self.part_id = None
     self.sql = SQLModel(run_id)
Example #2
0
class NewsModel():
	_DB_TABLE = 'newscraper'
	_LOG = logging.getLogger("NewsModel")

	def __init__(self, host, port, user, password, db_name):
		self.sqlmodel = SQLModel(host, port, user, password, db_name)

	def retrieve_news(self):
		news_query = f"SELECT url, publicationDate, newspaper, title, description, image FROM {NewsModel._DB_TABLE};"
		news_array = self.sqlmodel.retrieve(news_query)
		return news_array
Example #3
0
class OrganizationsModel:
    _DB_TABLE = 'organizations'
    _DB_TOKEN_TABLE = 'organizations_tokens'
    _LOG = logging.getLogger("OrganizationsModel")

    def __init__(self, host, port, user, password, db_name):
        self.sqlmodel = SQLModel(host, port, user, password, db_name)

    def retrieve_organizations(self):
        orgs_query = f"SELECT id, url, name, description FROM {OrganizationsModel._DB_TABLE};"
        orgs_array = self.sqlmodel.retrieve(orgs_query)
        for org in orgs_array:
            del org['id']
        return orgs_array
    def __init__(self,
                 run_id,
                 folder,
                 cameraname,
                 saturation=120,
                 minArea=200,
                 downsampling=2,
                 drawBoxes=True,
                 writeImages=False,
                 min_sharpness=200,
                 learningRate=0.001,
                 debug=False):
        self.run_id = run_id
        self.folder = folder
        self.cameraname = cameraname

        self.saturation = saturation
        self.minArea = minArea
        self.downsampling = downsampling
        self.drawBoxes = drawBoxes
        self.writeImages = writeImages
        self.min_sharpness = min_sharpness
        self.learningRate = learningRate
        self.debug = debug
        #print("self.saturation : "  + str(self.saturation))
        #print("self.downsampling : "  + str(self.downsampling))
        self.bpd = BasicPartsDetector(cameraname=self.cameraname,
                                      saturation=self.saturation,
                                      downsampling=self.downsampling,
                                      drawBoxes=self.drawBoxes,
                                      writeImages=self.writeImages,
                                      min_sharpness=self.min_sharpness,
                                      learningRate=self.learningRate,
                                      debug=self.debug)

        self.writeImages = writeImages
        self.newPartCounter = 1
        self.count = 1
        self.part_id = None
        self.sql = SQLModel(run_id)

        self.threshold_minx1 = (1920 / 334)
        self.threshold_minx2 = (1920 / 1568)
        self.threshold_miny = (1080 / 252)

        self.threshold_maxx1 = (1920 / 1)
        self.threshold_maxx2 = (1920 / 1920)
        self.threshold_maxy = (1080 / 1030)
        self.ct = CentroidTracker()
    def __init__(self,
                 run_id,
                 folder,
                 cameraname,
                 saturation=120,
                 minArea=100,
                 downsampling=2,
                 drawBoxes=True,
                 writeImages=False,
                 min_sharpness=200,
                 learningRate=0.001,
                 debug=False):
        self.run_id = run_id
        self.folder = folder
        self.cameraname = cameraname

        self.saturation = saturation
        self.minArea = minArea
        self.downsampling = downsampling
        self.drawBoxes = drawBoxes
        self.writeImages = writeImages
        self.min_sharpness = min_sharpness
        self.learningRate = learningRate
        self.debug = debug
        self.bpd = BasicPartsDetector(cameraname=self.cameraname,
                                      saturation=self.saturation,
                                      downsampling=self.downsampling,
                                      drawBoxes=self.drawBoxes,
                                      writeImages=self.writeImages,
                                      min_sharpness=self.min_sharpness,
                                      learningRate=self.learningRate,
                                      debug=self.debug)
        self.geometry = Geometry(debug=self.debug)
        self.boundary_left, self.boundary_right = self.geometry.getCameraNameBoundaries(
        )

        self.writeImages = writeImages
        self.newPartCounter = 1
        self.count = 1
        self.part_id = None
        self.sql = SQLModel(run_id)

        self.ct = CentroidTracker()
        self.calibrated = False
Example #6
0
 def __init__(self, host, port, user, password, db_name):
     self.sqlmodel = SQLModel(host, port, user, password, db_name)
Example #7
0
                                   folder,
                                   "USB",
                                   saturation=30,
                                   debug=debug,
                                   downsampling=downsampling,
                                   writeImages=write,
                                   learningRate=0.01)
camMotionBRIO = PartsDetectorBrioCam(run_id,
                                     folder,
                                     "BRIO",
                                     saturation=20,
                                     debug=debug,
                                     downsampling=downsampling,
                                     writeImages=write,
                                     learningRate=learningRateBrio)
sql = SQLModel(run_id)
filewriter = FileWriter(write, folder)
futureSession = FuturesSession()
control = Controllegosorter(futureSession)
predict = PredictController(futureSession)

if FileMode is False:
    control.startConveyor()
camMotionBRIO.warmup(webcamBRIO)


def downscale_preview(frame, cameraname, downscaling):
    if cameraname == "USB":
        return imutils.resize(frame, int(frame.shape[1] / downscaling))
    elif cameraname == "BRIO":
        return imutils.resize(frame, int(frame.shape[1] / (downscaling * 2)))
Example #8
0
class DetectPartsFromImages:
    def __init__(self, run_id, folder, writeImages = False):
        self.run_id = run_id
        self.folder = folder
        self.writeImages = writeImages
        self.newPartCounter = 1
        self.count = 1
        self.x_last = None
        self.y_last = None
        self.w_last = None
        self.h_last = None
        self.ts_last = None
        self.part_id = None
        self.sql = SQLModel(run_id)


    def detect(self, partimage):
        ts = time
        st = ts.strftime('%Y-%m-%d %H:%M:%S')
        # init if not set
        if self.x_last is None:
            self.x_last = partimage.x
            self.y_last = partimage.y
            self.w_last = partimage.w
            self.h_last = partimage.h
            self.ts_last = ts.time()
            self.part_id = self.sql.InsertIntoRecognisedParts()
        
        # calculate the difference of current parameters to parameters of last image
        x_diff = partimage.x - self.x_last
        y_diff = partimage.y - self.y_last

        if y_diff > 100:
            print("y_diff = " + str(y_diff) + " > 100 -> cancel image" )
            return
        
        # decide if deviation is to big, so it's probably a different part
        if y_diff < -25:
            #print("y_diff = " + str(y_diff) + " < -25 -> new Part")
            if self.writeImages:
                self.part_id =  self.sql.InsertIntoRecognisedParts()
            self.newPartCounter += 1
        elif abs(x_diff) > 150 :
            #print("abs(x_diff) = " + str(abs(x_diff)) + " > 150 -> new Part")
            if self.writeImages:
                self.part_id =  self.sql.InsertIntoRecognisedParts()
            self.newPartCounter += 1
        
        # Done- Set variables for next image
        self.x_last = partimage.x
        self.y_last = partimage.y
        self.w_last = partimage.w
        self.h_last = partimage.h
        self.ts_last = ts.time()

        st = ts.strftime('%Y-%m-%d %H:%M:%S')
        #Write file in folder
        filename = (self.folder+ "/"+ str(self.part_id) + "_" + str(self.count) + "_" + str(st).replace(":","_").replace(" ","_") + "_x" + str(partimage.x) + "_y" + str(partimage.y) + ".jpg")
        if self.writeImages:
            if not cv2.imwrite(filename,partimage.image):
                raise Exception("Could not write image " + filename) 
            else:
                self.count += 1
                # save imagespecs in Partimages-Table
                image_id =  self.sql.InsertIntoPartimages(filename,partimage.color, partimage.x, partimage.y, partimage.w, partimage.h, ts)
                #print("image_id:" + str(image_id))
                #print("filename " + filename)
                #print("x_diff: " + str(x_diff)  + "\n" 	+ "y_diff: " + str(y_diff)  + "\n" 	+ "w_diff: " + str(w_diff) + "\n"	+ "h_diff: " + str(h_diff) + "\n"	+ "ts_diff: " + str(ts_diff) + "\n")
                # Write a Line in RecognisedImages with the current Part_id
                self.sql.InsertIntoRecognisedImages(self.part_id,image_id)