催化读取QR码并在Arduino上采取行动

发布于 2025-01-26 16:51:38 字数 1439 浏览 3 评论 0原文

我正在使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

年少掌心 2025-02-02 16:51:38

我认为您想复制所有收到的一切。您将需要某种方法来知道何时完成传输。因此,在您的Python中:

def write_read(x):
  arduino.write(bytes(x, 'utf-8'))
  arduino.write(b'\n')
  time.sleep(0.05)
  data = arduino.readline()
  return data

然后,在Arduino Land,类似的东西:

void loop() {
  while (!Serial.available());
  digitalWrite(LED_BUILTIN, HIGH);
  while( (x = Serial.Read()) != '\n' )
  {
    Serial.print(x);
  }
  Serial.print('\n');
} 

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:

def write_read(x):
  arduino.write(bytes(x, 'utf-8'))
  arduino.write(b'\n')
  time.sleep(0.05)
  data = arduino.readline()
  return data

Then, in Arduino land, something like this:

void loop() {
  while (!Serial.available());
  digitalWrite(LED_BUILTIN, HIGH);
  while( (x = Serial.Read()) != '\n' )
  {
    Serial.print(x);
  }
  Serial.print('\n');
} 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文