コード例 #1
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
コード例 #2
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()