def do_snapshot():
    fname = 'img/' + str(time.time()) + '.jpg'
    ret, x, y = cap.cap(fname, 640, 480)
    if ret == 0:
        return 0, fname
    else:
        return -1, ''
Exemple #2
0
def claim(recipient, guarantee, outcome, funding, amount):
    cappedGuarantee = cap(guarantee, outcome)
    if overlap(recipient, cappedGuarantee, funding) >= amount:
        funding = funding - amount
        guarantee = remove(cappedGuarantee, recipient, amount)
        outcome = remove(outcome, recipient, amount)
    else:
        amount = 0

    return (amount, guarantee, outcome, funding)
Exemple #3
0
def readReg(lane, nameStr, convStr):
    """ read a register from cap """
    # suppress stdout for cap which by default displays the register name and
    # read-back
    save_stdout = sys.stdout
    sys.stdout = io.BytesIO()
    x = cap('rpt2', 'readfield', lane, nameStr,
            convStr)['Raptor2']['formatted']
    sys.stdout = save_stdout
    return x
Exemple #4
0
def main_loop(config_file):
    retcode, config_json = utils.gen_config(config_file)
    print 'mask_jon:', config_json

    while True:
        print(
            '---------------------------------------------------------------')
        t1 = time.time()
        f1 = utils.gen_filename(INPUT_FILE, t1)

        duration = config_json['duration']

        # create folder for img storing
        if os.path.exists('./img') == False:
            os.system('mkdir img')

        # call cap function to capture picture
        print 'f1:', f1
        ret, w, h = cap.cap(f1, 640, 480)
        if ret == -1:
            print 'capture image fail!'
        else:
            retcode = 0

            if config_json['cloud'] == 'oss':
                # upload file ...
                retcode = myoss.upload_file_to_oss(config_json['oss'], f1)

            elif config_json['cloud'] == 'bos':
                retcode = mybos.file_upload_bos(config_json['bos'], f1)
            else:
                print('no cloud defined, no file uploaded')

            print 'upload retcode:', retcode

        while (time.time() - t1) < duration:
            time.sleep(1)
Exemple #5
0
 def test_cap(self):
     text = 'aditya raj'
     result = cap.cap(text)
     self.assertEqual(result,'Aditya Raj')
    #print('Displaying image with objects detected in GUI')
    #print('Click in the GUI window and hit any key to exit')
    #display the filtered objects/boxes in a GUI window
    #display_objects_in_gui(display_image, filtered_objs)
    print('filtered_objs:',filtered_objs)
    print('time:',t2-t1)
    print('output share:',output.shape)


# main entry point for program. we'll call main() to do what needs to be done.
if __name__ == "__main__":
    retcode,graph = init_yolo()

    if retcode == 0:
        try:
            while True:
                ret,x,y = cap.cap('/run/now.jpg',640,480)
                if ret == 0:
                    yolo_detect(graph,'/run/now.jpg')
                else:
                    print('capture img fail')
                    
        except:
            #Clean up
            graph.DeallocateGraph()
            device.CloseDevice()
            print('Finished')
    else:
        print('yolo init fail')
        
import time, cap
fname = 'data/' + str(time.time()) + '.jpg'
ret, x, y = cap.cap(fname, 640, 480)
if ret == 0:
    print fname
else:
    pass
 def test_one_word(self):
     text = 'dupa'
     result = cap.cap(text)
     self.assertEqual(result, 'Dupa')
Exemple #9
0
def writeReg(lane, nameStr, value):
    """ write a register from cap """
    cap('rpt2', 'writefield', lane, nameStr, value)
Exemple #10
0
def main():
    """
    MAIN function, this runs automatically when trx_train_test.py is invoked
    """

    print "Begin TRX Train regression test"
    uart = UARTdump()
    uart.start()

    # specify ISI box channels to test
    channels = [0, 20, 40, 60, 80, 100]
    # specify number of runs per channel
    runs = 20

    init_script = script_path + '\\' + script_name
    # reset DUT and run an init script
    cap('rpt2', 'cmd', 'RPT DUT RESET')
    cap('rpt2', 'cmd', 'RPT SCRIPT RUN ' + init_script)

    init_channel()  # init the ISI box
    on('PT_EN_LANE')  # phy_test is enabled for then entire regression
    # ensure that the PHY test pattern is PRBS-31
    write('PT_TX_PATTERN_SEL_LANE[5:0]', 0x1A)
    write('PT_RX_PATTERN_SEL_LANE[5:0]', 0x1A)

    # BER will hold the measured BER for each run
    BER = [[0 for x in range(runs)] for y in range(len(channels))]
    # FAIL will be 1 if the test does not pass the regression criteria
    FAIL = [[0 for x in range(runs)] for y in range(len(channels))]

    for i in range(len(channels)):
        channel(channels[i])  # change ISI box to current channel
        ber_total = 0
        fail = 0

        for x in range(0, runs):
            # write a unique runcode to the debugdump file (so we can uniquely
            # identify them later)
            runcode = 'runcode:%d.%d' % (i, x)
            uart.write(runcode)

            # START: TRX Train
            on('tx_train_enable_lane')
            train_timeout = 20
            while (read('train_done_lane') == 0 and train_timeout > 0):
                time.sleep(1)
                train_timeout -= 1
            time.sleep(1)
            off('tx_train_enable_lane')
            # END: TRX Train

            if (train_timeout == 0):
                print "Training timed out!!!"
                fail += 1
                FAIL[i][x] = 1
                BER[i][x] = -1
                time.sleep(5)
                continue

            time.sleep(1)  # wait 1 second after train to settle everything

            if (not (read('PT_LOCK_LANE'))):
                print "Pattern cannot lock!!!"
                fail += 1
                FAIL[i][x] = 1
                BER[i][x] = -1
                continue

            print("Measuring BER...")
            ber_time = 20
            # count errors for ber_time seconds

            # START: measure BER
            toggle('PT_CNT_RST_LANE')
            time.sleep(ber_time)

            on('pt_cnt_pause_lane')
            error_count = read('PT_ERR_CNT_LANE[31:0]')
            error_count += read('PT_ERR_CNT_LANE[47:32]') << 32
            symbol_count = read('PT_CNT_LANE[31:0]')
            symbol_count += read('PT_CNT_LANE[47:32]') << 32
            symbol_count *= 80
            off('pt_cnt_pause_lane')
            # END: measure BER

            measured_ber = float(error_count) / symbol_count
            ber_calc_results = (measured_ber, error_count, symbol_count)
            print "BER = (%.3e, (%d / %d)" % ber_calc_results
            ber_total += measured_ber
            if measured_ber > 1e-4:
                print "BER failed threshold!"
                fail += 1
                FAIL[i][x] = 1
            print fail, "failures /", x + 1, "runs"
            print "Average BER =", ber_total / (x + 1)
            BER[i][x] = measured_ber
        average_ber = ber_total / (runs)
        print "Overall Average BER =", average_ber
        print fail, "failures /", runs, "runs"
    write_to_file([channels, BER, FAIL])  # write results.json
    summary()  # print out a summary in stdout (uses the results.json file)
    uart.close()
	def test_two_words(self):
		r = cap.cap('no name')
		self.assertEqual(r,'No Name')
	def test_one_word(self):
		r = cap.cap('name') # run the function
		self.assertEqual(r,'Name') # compare the outputs using assertEqual method inherited from unittest
Exemple #13
0
        rotate_base = config_json['rotate_base']
        duration = config_json['duration']

        points_src = config_json['transform_src']
        points_des = config_json['transform_des']
        seg_points = config_json['seg_points']
        seg_group_map = config_json['seg_group_map']            
        run_mode = config_json['run_mode']
        
        # create folder for img storing
        if os.path.exists('./img') == False:
            os.system('mkdir img')

        # call cap function to capture picture
        print 'f1:',f1
        ret,w,h = cap.cap(f1,640,480)    
        if ret == -1:
            print 'capture image fail!'
        else:
            print 'f2:',f2
            try:
                if retcode == 0:

                    
                    if os.path.exists(f1):        
                        #img = cv2.imread(f2)
                        #          y y+h x x+w
                        raw_image = cv2.imread(f1)

                        if len(points_src) == 4 and len(points_des) == 4:
                            print 'step 1 =================> do transforming ...'
Exemple #14
0
 def test_multiple_words(self):
     text = 'monty python'
     result = cap.cap(text)
     self.assertEqual(result,'Monty Python')
Exemple #15
0
 def test_one_word(self):
     text = 'python'
     result = cap.cap(text)
     self.assertEqual(result,'Python')