Пример #1
0
class MyFuncs:
    def init(self):
        nameLog = timeName("", "", "")
        self.logs = open(
            "/home/pi/git/RasPI_and_robots/logs/detection" + nameLog + ".txt",
            "a")
        self.stream = io.BytesIO()
        self.camera = picamera.PiCamera()
        self.camera.resolution = (640, 480)
        #        self.camera.EXPOSURE_MODES = 8
        time.sleep(2)
        self.A = Digit_detect('', 24)
        self.A.learn_from_file('/home/pi/git/RasPI_and_robots/new_samples',
                               '/home/pi/git/RasPI_and_robots/new_responses')
        self.index = 0
        return 1

    def step(self):
        print "STEP"
        self.camera.capture(self.stream, format='jpeg')
        #    Construct a numpy array from the stream
        data = np.fromstring(self.stream.getvalue(), dtype=np.uint8)
        #    "Decode" the image from the array, preserving colour
        image = cv2.imdecode(data, 1)
        self.stream.seek(0)
        self.stream.truncate()
        filename = timeName("/home/pi/git/RasPI_and_robots/logs/image_",
                            ".jpg", "%03d" % self.index)
        cv2.imwrite(filename, image)
        self.index += 1
        print filename
        try:
            detected = self.A.detect_digits(image)
        except:
            print "EXCEPTION"
            detected = [999]
        print detected
        self.logs.write(
            filename.split("/")[-1] + '\t' + str(detected) + "\r\n")
        self.logs.flush()
        return [filename.split("/")[-1]] + detected

    def term(self):
        self.logs.close()
        self.camera.close()
        self.logs = None
        self.camera = None
        self.stream = None
        return 1
Пример #2
0
 def init(self):
     nameLog = timeName("", "", "")
     self.logs = open(
         "/home/pi/git/RasPI_and_robots/logs/detection" + nameLog + ".txt",
         "a")
     self.stream = io.BytesIO()
     self.camera = picamera.PiCamera()
     self.camera.resolution = (640, 480)
     #        self.camera.EXPOSURE_MODES = 8
     time.sleep(2)
     self.A = Digit_detect('', 24)
     self.A.learn_from_file('/home/pi/git/RasPI_and_robots/new_samples',
                            '/home/pi/git/RasPI_and_robots/new_responses')
     self.index = 0
     return 1
Пример #3
0
class MyFuncs:
    def init( self ):
        nameLog = timeName("", "", "")
        self.logs = open("/home/pi/git/RasPI_and_robots/logs/detection"+nameLog+".txt", "a")
        self.stream = io.BytesIO()
        self.camera = picamera.PiCamera()
        self.camera.resolution = (640, 480)
#        self.camera.EXPOSURE_MODES = 8
        time.sleep(2)
        self.A = Digit_detect('',24)
        self.A.learn_from_file('/home/pi/git/RasPI_and_robots/new_samples','/home/pi/git/RasPI_and_robots/new_responses')
        self.index = 0
        return 1

    def step( self ):
        print "STEP"
        self.camera.capture(self.stream, format='jpeg')
        #    Construct a numpy array from the stream
        data = np.fromstring(self.stream.getvalue(), dtype=np.uint8)
        #    "Decode" the image from the array, preserving colour
        image = cv2.imdecode(data, 1)
        self.stream.seek(0)
        self.stream.truncate()
        filename = timeName( "/home/pi/git/RasPI_and_robots/logs/image_", ".jpg", "%03d" % self.index )
        cv2.imwrite( filename, image )
        self.index += 1
        print filename
        try:
           detected = self.A.detect_digits(image)
        except:
           print "EXCEPTION"
           detected = [999]
        print detected
        self.logs.write(filename.split("/")[-1] +'\t'+ str(detected ) + "\r\n")
        self.logs.flush()
        return [filename.split("/")[-1]] + detected

    def term( self ):
        self.logs.close()
        self.camera.close()
        self.logs = None
        self.camera = None
        self.stream = None
        return 1
Пример #4
0
    def init( self ):
        nameLog = timeName("", "", "")
        self.logs = open("/home/pi/git/RasPI_and_robots/logs/detection"+nameLog+".txt", "a")
        self.stream = io.BytesIO()
        self.camera = picamera.PiCamera()
        self.camera.resolution = (640, 480)
#        self.camera.EXPOSURE_MODES = 8
        time.sleep(2)
        self.A = Digit_detect('',24)
        self.A.learn_from_file('/home/pi/git/RasPI_and_robots/new_samples','/home/pi/git/RasPI_and_robots/new_responses')
        self.index = 0
        return 1
Пример #5
0
def sickMain( workingTime = 60, saving = True ):
    detected = []
    logs = open("/home/pi/git/RasPI_and_robots/logs/detection.txt", "a")
    stream = io.BytesIO()
    camera = picamera.PiCamera()
    camera.resolution = (640, 480)
#    camera.start_preview()
    time.sleep(2)
    A=Digit_detect('',20)
    A.learn_from_file('/home/pi/git/RasPI_and_robots/samples.data','/home/pi/git/RasPI_and_robots/responses.data')
    index = 0
    timeStart = time.time()
    actulalTime = time.time()
    while timeStart > actulalTime - workingTime:
        actulalTime = time.time()
        
        camera.capture(stream, format='jpeg')
        #    Construct a numpy array from the stream
        data = np.fromstring(stream.getvalue(), dtype=np.uint8)
        #    "Decode" the image from the array, preserving colour
        image = cv2.imdecode(data, 1)
        stream.seek(0)
        stream.truncate()
        
        if saving:
#            actualTime = time.time()
            filename = timeName( "/home/pi/git/RasPI_and_robots/logs/image_", ".jpg", "%03d"%index )
#            camera.capture( filename )
            cv2.imwrite( filename, image )
            index = index + 1
#        print A.detect_digits_from_file('SICK_ROBOT/001.jpg')
        print filename
#        detected = A.detect_digits_from_file(filename)
        detected = A.detect_digits(image)
        print detected
        logs.write(filename.split("/")[-1] + str(detected ) + "\r\n")
        logs.flush()
    
    logs.close()