2017-07-14 89 views
0

我收到错误:ValueError异常:无效字面对于int()与基体10:'20 r xfa20'

ValueError:invalid literal for int() with base 10 : '20\r\xfa20' 

在这部分代码:

while True: 
    ret, im = cam.read() 
    gray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY) 
    faces = faceCascade.detectMultiScale(gray, 1.2, 5) 
    for(x, y, w, h) in faces: 
     a = ser.readline() 
     b = int((a).strip()) 
     print(int(a)) 
     cv2.rectangle(im, (x, y), (x+w, y+h), (225, 0, 0), 2) 
     Id, conf = recognizer.predict(gray[y:y+h, x:x+w]) 
     print conf 
     if(conf < 50): 
      if(Id == 1): 
       Id = "disheet" 
       if(count1 == 0): 
        GPIO.output(13, GPIO.HIGH) 
        ser.write('d') 

我我正在连续发送来自Arduino的20,以便Pi和Arduino之间的通信将开始。

+0

你能告诉我们你是从阅读本'ser'文件的内容?它看起来像不包含完整的字符串表示形式 – KGS

+1

问题是2“20”值之间的'\ r \ xfa',它似乎是某种控制序列('\ r'是_CR_字符)。阅读时,你可以对该序列进行拆分,但这是纯粹的猜测。 – CristiFati

+0

@service的KGS值是0,1,2 .... 12 –

回答

0
+0

是的,我检查,但这不适合我 –

+0

对不起,听到这一点。然后我认为它与控制序列有关,因为@CristiFati在上面已经提到它。为避免出现这种情况,请务必设置r'20 \ r \ xfa20'之类的字符串。这样控制顺序将被忽略。如果您告诉我们错误发生在哪一行,我认为这也会很有趣。 –

相关问题