Jetson Nano and OpenCV: Showing the co-ordinates of mouse click

Soo in this project we will be able to see the co-ordinates of the area that we click with the cursor.

Demo:

Things Required:

  1. Jetson Nano
  2. Keyboard
  3. Mouse
  4. HDMI Screen
  5. Raspberry Pi Camera
  6. External Power Supply

Reference Material:

  1. Video that I followed for this project: (LINK)

Code:

Note that code below is in python

View on/Download from Github: (LINK)

import cv2
evt=-1
def click(event, x, y, flags, params):
    global pnt 
    global evt
    if(event == cv2.EVENT_LBUTTONDOWN):
        print('Mouse event was: ', event)
        print(x,',',y)
        pnt=(x,y)
        evt=event

dispW=640
dispH=480
flip=2
cv2.namedWindow('nanoCam')
cv2.setMouseCallback('nanoCam', click)
camSet='nvarguscamerasrc !  video/x-raw(memory:NVMM), width=3264, height=2464, format=NV12, framerate=21/1 ! nvvidconv flip-method='+str(flip)+' ! video/x-raw, width='+str(dispW)+', height='+str(dispH)+', format=BGRx ! videoconvert ! video/x-raw, format=BGR ! appsink'
cam=cv2.VideoCapture(camSet)
while True:
    ret, frame=cam.read()
    if evt == 1:
        cv2.circle(frame, pnt, 10, (0,0,255), -1)
        font= cv2.FONT_HERSHEY_PLAIN
        myStr= str(pnt)
        cv2.putText(frame,myStr, pnt, font, 1, (255,0,0),2)
    cv2.imshow('nanoCam',frame)
    if cv2.waitKey(1)==ord('q'):
        break
cam.release()
cv2.destroyAllWindows()

Stay Tuned for upcoming posts on Jetson Nano and AI Projects! Want to be the first to know when a new and amazing post comes up?? Then feel free to subscribe!

Happy Learning!!

This image has an empty alt attribute; its file name is stay-tuned.gif

Leave a Reply

PHP JS HTML CSS BASH PYTHON CODE

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this:
search previous next tag category expand menu location phone mail time cart zoom edit close