0

I want to send data python to arduino. Actually, I can send it with another code. Communication is not a problem for me. I trained a model for two signs (on and off). When I show on sign, led will open, and when I show off-sign, led will off. But my problem is I cant call signs and send data. How can I call signs in code? Is anybody know that? off sign

My code:

while True: 
    
    ret, frame = cap.read()
    frame = cv2.flip(frame, 1)
    image_np = np.array(frame)
    input_tensor = tf.convert_to_tensor(np.expand_dims(image_np, 0), dtype=tf.float32)
    detections = detect_fn(input_tensor)
    
    num_detections = int(detections.pop('num_detections'))
    detections = {key: value[0, :num_detections].numpy()
                  for key, value in detections.items()}
    detections['num_detections'] = num_detections

    # detection_classes should be ints.
    detections['detection_classes'] = detections['detection_classes'].astype(np.int64)

    label_id_offset = 1
    image_np_with_detections = image_np.copy()
    
    viz_utils.visualize_boxes_and_labels_on_image_array(
                image_np_with_detections,
                detections['detection_boxes'],
                detections['detection_classes']+label_id_offset,
                detections['detection_scores'],
                category_index,
                use_normalized_coordinates=True,
                max_boxes_to_draw=1,
                min_score_thresh=.5,
                agnostic_mode=False)   
   

    cv2.imshow('object detection',  cv2.resize(image_np_with_detections, (800, 600)))
                
    if cv2.waitKey(1) & 0xFF == ord('q'):
        cap.release()
        cv2.destroyAllWindows()
        ArduinoSerial.close() 
        break
4
  • what do you mean by calling sign? as I understand sign can be 0 or 1 Commented Mar 28, 2021 at 17:03
  • I trained a model for two signs (on and off). I upload sign of off image. I want to show sign with my hand at webcam and control the arduino led. Commented Mar 28, 2021 at 20:50
  • Do you want your model to run on arduino, or send data to arduino? Commented Mar 29, 2021 at 10:33
  • I already trained model. I just want to when i show on sign on webcam, at arduino led will on. Yes i want to send data. Commented Mar 29, 2021 at 11:07

1 Answer 1

1

If you're trying to get python code to control an Arduino a simple way may be over serial. I found a pretty good discussion about it here they talk about needing PySerial so be prepared to need to install at least an extra library.

You can send what ever you want to the Arduino (via serial) and when the Arduino receives serial data it can simply toggle the led on its end.

Sign up to request clarification or add additional context in comments.

3 Comments

I can send data to arduino no problem here. I trained model for two hand signs. My problem is when i show on sign on webcam light arduinos led. I tried something like that but it didnt work. if (detections['detection_classes'] == "open"): ArduinoSerial.write('1'.encode())
I think i misrepresented myself. I want to print the detected sign on the screen.
ahhh you want to display "open" or "closed" on the display of the machine running the tensorflow program? If thats the case then try pygame for simple window popout that you can draw in (or write open/closed). before i post this i see you're using opencv and may already have windows open showing the webcam, in that case you can just type some text into one of those windows.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.