Soo here I’ve made a project in which you can click on any point on the camera display screen and obtain the exact proportions of BGR (blue, green, red) at that point/pixel.
Demo:
Things Required:
- Jetson Nano
- Keyboard
- Mouse
- HDMI Screen
- Raspberry Pi Camera
- External Power Supply
Reference Material:
- Video that I followed for this project: (LINK)
Code:
Note that code below is in python
View on/Download from Github: (LINK)
import cv2
import numpy as np
evt=-1
coord=[]
img=np.zeros((250,250,3),np.uint8)
def click (event, x,y,flags, params):
global pnt
global evt
if event == cv2.EVENT_LBUTTONDOWN:
print('Mouse event was: ', event)
pnt=(x,y)
coord.append(pnt)
#print(coord)
evt=event
if event == cv2.EVENT_RBUTTONDOWN:
print(x,y)
blue=frame[y,x,0]
green=frame[y,x,1]
red= frame[y,x,2]
print(blue,green,red)
colorString= str(blue)+','+str(green)+','+str(red)
img[:]=[blue,green,red]
fnt= cv2.FONT_HERSHEY_PLAIN
r=255-int(red)
g=255-int(green)
b=255-int(blue)
tp=(b,g,r)
cv2.putText(img, colorString, (10,25), fnt, 1, tp, 2)
cv2.imshow('color',img)
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()
for pnts in coord:
cv2.circle(frame, pnts, 5, (0,0,255),-1)
font= cv2.FONT_HERSHEY_PLAIN
myStr= str(pnts)
cv2.putText(frame, myStr, pnts, font, 1,(255,0,0),2)
cv2.imshow('nanoCam', frame)
keyEvent= cv2.waitKey(1)
if keyEvent == ord('q'):
break
if keyEvent == ord('c'):
coord=[]
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!!
