Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Info

see https://www.tomshardware.com/news/raspberry-pi-opencv-distance-detection



20 changes: 10 additions & 10 deletions handdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,33 @@ def obj_data(img):
def Distance_finder(Focal_Length, Known_width, obj_width_in_frame):
distance = (Known_width * Focal_Length)/obj_width_in_frame
return distance
ref_image = cv2.imread("rf.png")
ref_image = cv2.imread("/tmp/rf.png")
ref_image_obj_width = obj_data(ref_image)
Focal_length_found = Focal_Length_Finder(Known_distance, Known_width, ref_image_obj_width)
cv2.imshow("ref_image", ref_image)

print(Focal_length_found)


while True:
ret,frame=cap.read()
frame=cv2.flip(frame,1)
obj_width_in_frame=obj_data(frame)
if not obj_width_in_frame:
print("no hands")
else:
else:
Distance = Distance_finder(Focal_length_found, Known_width, obj_width_in_frame)
for i in a:
x1=i[0]
y1=i[1]

cv2.putText(frame, f"Distance: {round(Distance,2)} CM", (x1, y1),cv2.FONT_HERSHEY_PLAIN, 2, (255,0,0), 2)



frame=cv2.imshow("FRAME",frame)

if cv2.waitKey(1)&0xFF==27:
break
cap.relase()
cv2.destroyAllWindows()
cap.release()
cv2.destroyAllWindows()
4 changes: 2 additions & 2 deletions img.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
cv2.imshow('FRAME',frame)
if cv2.waitKey(1) == ord('a'):
print ("pressed a")
frame=cv2.imwrite("/home/pi/hand-distance/rf.png",frame)
frame=cv2.imwrite("/tmp/rf.png",frame)
break

cap.release()
cv2.destroyAllWindows()
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
opencv-python
cvzone
mediapipe