催化读取QR码并在Arduino上采取行动
我正在使用OpenCV和Pyzbar读取QR码,我正在与Arduino uno进行pyserial进行交流。
我的python代码
from pyzbar.pyzbar import decode
import cv2
import serial
import time
arduino = serial.Serial(port='COM6', baudrate=115200, timeout=1)
def write_read(x):
arduino.write(bytes(x, 'utf-8'))
time.sleep(0.05)
data = arduino.readline()
return data
cap = cv2.VideoCapture(0)
def get_qr_data(input_frame):
try:
return decode(input_frame)
except:
return []
while True:
_, frame = cap.read()
qr_obj = get_qr_data(frame)
cv2.imshow("DD", frame)
print(qr_obj)
# cv2.imshow("DD2", frame2)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
来自qr_obj = get_qr_data(frame)
i获得结果[decoded(data ='asd',type ='qrcode',rect = ect = ect = ect = rect = ect = 115,top = 155,top = 1555 ,宽度= 225,高度= 223),polygon = [point(x = 115,y = 378),point(x = 340,y = 370),点(x = 335,y = 155),点(x = = 119,y = 155)],质量= 1,entirentation ='up')]
我试图在arduino串行显示器中打印QR数据,并打开内置的arduino in in led
arduino代码
char x;
void setup() {
Serial.begin(115200);
Serial.setTimeout(1);
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
while (!Serial.available());
x = Serial.read();
Serial.println(x);
if(Serial.read() == x)
{
digitalWrite(LED_BUILTIN, HIGH);
}
}
my 't打开,串行监视器中没有写任何东西
I'm reading qr code using opencv and pyzbar, i'm communicating with an arduino uno using pyserial.
my python code
from pyzbar.pyzbar import decode
import cv2
import serial
import time
arduino = serial.Serial(port='COM6', baudrate=115200, timeout=1)
def write_read(x):
arduino.write(bytes(x, 'utf-8'))
time.sleep(0.05)
data = arduino.readline()
return data
cap = cv2.VideoCapture(0)
def get_qr_data(input_frame):
try:
return decode(input_frame)
except:
return []
while True:
_, frame = cap.read()
qr_obj = get_qr_data(frame)
cv2.imshow("DD", frame)
print(qr_obj)
# cv2.imshow("DD2", frame2)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
from qr_obj = get_qr_data(frame)
i get the result [Decoded(data='asd', type='QRCODE', rect=Rect(left=115, top=155, width=225, height=223), polygon=[Point(x=115, y=378), Point(x=340, y=370), Point(x=335, y=155), Point(x=119, y=155)], quality=1, orientation='UP')]
im trying to print the qr data in arduino serial monitor and turn on the arduino built in led
my arduino code
char x;
void setup() {
Serial.begin(115200);
Serial.setTimeout(1);
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
while (!Serial.available());
x = Serial.read();
Serial.println(x);
if(Serial.read() == x)
{
digitalWrite(LED_BUILTIN, HIGH);
}
}
The built in led doesn't turn on and nothing is written in the serial monitor
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您想复制所有收到的一切。您将需要某种方法来知道何时完成传输。因此,在您的Python中:
然后,在Arduino Land,类似的东西:
I assume you want to copy everything you get. You will need some way to know when the transmission is complete. So, in your Python:
Then, in Arduino land, something like this: