diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..a53d962
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+*.mp4
\ No newline at end of file
diff --git a/Capture_Reference_image/Capture_Reference_Image.py b/Capture_Reference_image/Capture_Reference_Image.py
index f034a94..1b37254 100644
--- a/Capture_Reference_image/Capture_Reference_Image.py
+++ b/Capture_Reference_image/Capture_Reference_Image.py
@@ -1,63 +1,63 @@
-
-import cv2
-import time
-import os
-# chose your camera number:
-cam_number =2
-camera = cv2.VideoCapture(cam_number)
-starting_time =time.time()
-Frame_Counter= 0
-Cap_frame =0
-Dir_name = "capture_images"
-number_image_captured =20
-capture_image=False
-while True:
- # checking the Directory Exist or not .
- IsDirExist = os.path.exists(Dir_name)
- print(IsDirExist)
- # if there is no Directory named "capture_image", simply create it. using os
- if not IsDirExist:
- os.mkdir(Dir_name)
-
- Frame_Counter+=1
- # reading the frames from camera
- ret, frame = camera.read()
- # reading saving frame seperatly
- ret, saving_frame = camera.read()
- # finding with and height of image
- height, width, dim = saving_frame.shape
- # print(width, height, dim)
-
- # writing the width and height of on the image saving image
- cv2.putText(saving_frame, f"Height: {height}", (30, 50), cv2.FONT_HERSHEY_COMPLEX, 0.4, (0,255,0),1)
- cv2.putText(saving_frame, f"Width: {width}", (30, 70), cv2.FONT_HERSHEY_COMPLEX, 0.4, (0,255,0),1)
- # capture frame if capture_image is ture and number_image_captured are less then 10
- # if we press 'c' on keyboard then capture_image become 'True'
- if capture_image==True and Cap_frame <= number_image_captured:
- Cap_frame+=1
- cv2.putText(frame, 'Capturing', (50, 70), cv2.FONT_HERSHEY_COMPLEX, 2, (0,244, 255),1)
- cv2.imwrite(f"{Dir_name}/frame-{Cap_frame}.png", saving_frame)
- else:
- cv2.putText(frame, 'Not Capturing', (50, 70), cv2.FONT_HERSHEY_COMPLEX, 2, (255,0, 255),1)
- Cap_frame =0
- capture_image =False
- cv2.imshow("frame", frame)
- cv2.imshow("saving Image", saving_frame)
- total_time = time.time()
- frame_time=total_time -starting_time
- # calculating how much frame pass in each second
-
- fps = Frame_Counter/frame_time
- # print(fps)
- # print(capture_image)
- # when we press 'q' it quites the program
- if cv2.waitKey(1) == ord('q'):
- break
- # if we press 'c' on the keyboard then it starts capturing the images.
- if cv2.waitKey(1)==ord('c'):
- capture_image= True
-
-# finally closing the camera
-camera.release()
-# closing all opend windows
+
+import cv2
+import time
+import os
+# chose your camera number:
+cam_number =2
+camera = cv2.VideoCapture(cam_number)
+starting_time =time.time()
+Frame_Counter= 0
+Cap_frame =0
+Dir_name = "capture_images"
+number_image_captured =20
+capture_image=False
+while True:
+ # checking the Directory Exist or not .
+ IsDirExist = os.path.exists(Dir_name)
+ print(IsDirExist)
+ # if there is no Directory named "capture_image", simply create it. using os
+ if not IsDirExist:
+ os.mkdir(Dir_name)
+
+ Frame_Counter+=1
+ # reading the frames from camera
+ ret, frame = camera.read()
+ # reading saving frame seperatly
+ ret, saving_frame = camera.read()
+ # finding with and height of image
+ height, width, dim = saving_frame.shape
+ # print(width, height, dim)
+
+ # writing the width and height of on the image saving image
+ cv2.putText(saving_frame, f"Height: {height}", (30, 50), cv2.FONT_HERSHEY_COMPLEX, 0.4, (0,255,0),1)
+ cv2.putText(saving_frame, f"Width: {width}", (30, 70), cv2.FONT_HERSHEY_COMPLEX, 0.4, (0,255,0),1)
+ # capture frame if capture_image is ture and number_image_captured are less then 10
+ # if we press 'c' on keyboard then capture_image become 'True'
+ if capture_image==True and Cap_frame <= number_image_captured:
+ Cap_frame+=1
+ cv2.putText(frame, 'Capturing', (50, 70), cv2.FONT_HERSHEY_COMPLEX, 2, (0,244, 255),1)
+ cv2.imwrite(f"{Dir_name}/frame-{Cap_frame}.png", saving_frame)
+ else:
+ cv2.putText(frame, 'Not Capturing', (50, 70), cv2.FONT_HERSHEY_COMPLEX, 2, (255,0, 255),1)
+ Cap_frame =0
+ capture_image =False
+ cv2.imshow("frame", frame)
+ cv2.imshow("saving Image", saving_frame)
+ total_time = time.time()
+ frame_time=total_time -starting_time
+ # calculating how much frame pass in each second
+
+ fps = Frame_Counter/frame_time
+ # print(fps)
+ # print(capture_image)
+ # when we press 'q' it quites the program
+ if cv2.waitKey(1) == ord('q'):
+ break
+ # if we press 'c' on the keyboard then it starts capturing the images.
+ if cv2.waitKey(1)==ord('c'):
+ capture_image= True
+
+# finally closing the camera
+camera.release()
+# closing all opend windows
cv2.destroyAllWindows()
\ No newline at end of file
diff --git a/Capture_Reference_image/Distance_Measurement.py b/Capture_Reference_image/Distance_Measurement.py
index 88010a6..2e83075 100644
--- a/Capture_Reference_image/Distance_Measurement.py
+++ b/Capture_Reference_image/Distance_Measurement.py
@@ -1,54 +1,54 @@
-import cv2 as cv
-
-
-# data
-Know_distance =30 # in centimeters
-#mine is 14.3 something, measure your face width, are google it
-Know_width_face =14.3 #centimeters
-# chose your camera
-cam_number =1
-face_detector = cv.CascadeClassifier('data/haarcascade_frontalface_default.xml')
-camera = cv.VideoCapture(cam_number)
-def FocalLengthFinder(Measured_distance, real_width_of_face, width_of_face_in_image):
- # finding focal length
- focal_length = (width_of_face_in_image* Measured_distance)/real_width_of_face
- return focal_length
-
-def Distance_Measurement(face_real_width, Focal_Length, face_with_in_image):
- distance= (face_real_width * Focal_Length)/face_with_in_image
- return distance
-def Face_Detection(image):
- f_width =0
- Gray_image = cv.cvtColor(image, cv.COLOR_BGR2GRAY)
- faces = face_detector.detectMultiScale(Gray_image, 1.3, 5)
- for (x, y, h, w) in faces:
- cv.rectangle(image, (x,y), (x+w, y+h), (255,255,255), 1)
- f_width =w
- print(f_width)
- return f_width, image
-reference_image =cv.imread("rf.png")
-face_w , image_read= Face_Detection(reference_image)
-cv.imshow("ref", image_read)
-calculate_focal_length =FocalLengthFinder(Know_distance, Know_width_face,face_w)
-print(calculate_focal_length)
-font = cv.FONT_HERSHEY_SIMPLEX
-while True:
- ret, frame = camera.read()
- height, width, dim = frame.shape
- # change the color of image
- # print(height, width)
- Gray_image = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
- faces = face_detector.detectMultiScale(Gray_image, 1.3, 5)
- for (x, y, h, w) in faces:
- cv.rectangle(frame, (x,y), (x+w, y+h), (255,255,255), 1)
- distance =Distance_Measurement(Know_width_face,calculate_focal_length, w)
- print(distance)
-
- cv.putText(frame, f" Distance = {distance}", (50,50),font, 0.7, (0,255,0), 3)
-
- cv.imshow('frame', frame)
-
- if cv.waitKey(1)==ord('q'):
- break
-camera.release()
-cv.destroyAllWindows()
+import cv2 as cv
+
+
+# data
+Know_distance =30 # in centimeters
+#mine is 14.3 something, measure your face width, are google it
+Know_width_face =14.3 #centimeters
+# chose your camera
+cam_number =1
+face_detector = cv.CascadeClassifier('data/haarcascade_frontalface_default.xml')
+camera = cv.VideoCapture(cam_number)
+def FocalLengthFinder(Measured_distance, real_width_of_face, width_of_face_in_image):
+ # finding focal length
+ focal_length = (width_of_face_in_image* Measured_distance)/real_width_of_face
+ return focal_length
+
+def Distance_Measurement(face_real_width, Focal_Length, face_with_in_image):
+ distance= (face_real_width * Focal_Length)/face_with_in_image
+ return distance
+def Face_Detection(image):
+ f_width =0
+ Gray_image = cv.cvtColor(image, cv.COLOR_BGR2GRAY)
+ faces = face_detector.detectMultiScale(Gray_image, 1.3, 5)
+ for (x, y, h, w) in faces:
+ cv.rectangle(image, (x,y), (x+w, y+h), (255,255,255), 1)
+ f_width =w
+ print(f_width)
+ return f_width, image
+reference_image =cv.imread("rf.png")
+face_w , image_read= Face_Detection(reference_image)
+cv.imshow("ref", image_read)
+calculate_focal_length =FocalLengthFinder(Know_distance, Know_width_face,face_w)
+print(calculate_focal_length)
+font = cv.FONT_HERSHEY_SIMPLEX
+while True:
+ ret, frame = camera.read()
+ height, width, dim = frame.shape
+ # change the color of image
+ # print(height, width)
+ Gray_image = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
+ faces = face_detector.detectMultiScale(Gray_image, 1.3, 5)
+ for (x, y, h, w) in faces:
+ cv.rectangle(frame, (x,y), (x+w, y+h), (255,255,255), 1)
+ distance =Distance_Measurement(Know_width_face,calculate_focal_length, w)
+ print(distance)
+
+ cv.putText(frame, f" Distance = {distance}", (50,50),font, 0.7, (0,255,0), 3)
+
+ cv.imshow('frame', frame)
+
+ if cv.waitKey(1)==ord('q'):
+ break
+camera.release()
+cv.destroyAllWindows()
diff --git a/README.md b/README.md
index 308f4cc..7a98897 100644
--- a/README.md
+++ b/README.md
@@ -1,20 +1,144 @@
-# Distance_measurement_using_single_camera
-
-
-## Clone this Repo:
-git clone https://github.com/Asadullah-Dal17/Distance_measurement_using_single_camera
-
-## install Opencv-python on Windows
-pip install opencv-python
-
-install Opencv-python on Linux or Mac
-pip3 install opencv-python
-
-# Run the code
-## windows:
-python distance.py
-## linux or Mac:
-python3 distance.py
-
-Youtube Video: https://youtu.be/zzJfAw3ASzY
-
+# Distance measurement using single:one:camera :camera:
+
+  
+
+If you want to estimate distance of objects with your simple webcam, then this algorithm(*Triangle similarity*) would be helpful for you to find Distance *from object to camera*, I have provide to two examples, one is simple **face detection and distance Estimation**, other is **Yolo4 object detection and distance Estimation**
+
+Here in this readme file you will get short description, if need more details, then you can watch video tutorial on YouTube as well.
+
+## Distance & Speed Estimation Demo
+
+https://user-images.githubusercontent.com/66181793/122644855-bb8ac000-d130-11eb-85c3-c7ff4bd6474c.mp4
+
+### Video Tutorials
+
+[**Distance Estimation Youtube Tutorail**](https://youtu.be/zzJfAw3ASzY) 
+
+[**Distance & Speed Estimation Youtube Tutorial**](https://youtu.be/DIxcLghsQ4Q) 
+
+[**YoloV4 Object Detection & Distance Estimation**](https://youtu.be/FcRCwTgYXJw) 
+[*Project GitHub Repository*](https://github.com/Asadullah-Dal17/Yolov4-Detector-and-Distance-Estimator)
+
+## YoloV4 Distance Estimation
+
+https://user-images.githubusercontent.com/66181793/124917186-f5066b00-e00c-11eb-93cf-24d84e9c2e7a.mp4
+
+## Distance Estimation on Raspberry Pi 🍓
+
+https://user-images.githubusercontent.com/66181793/138200943-74d28b4d-bd0e-49fd-8836-4a01b35118eb.mp4
+
+✔️ here is source code and details for Instllation of Opencv-python on 🍓 Pi 😃 [Distance Estimation on Raspberry pi 🍓](https://github.com/Asadullah-Dal17/Distance_measurement_using_single_camera/tree/main/Raspberry_pi)
+
+
+:heavy_check_mark: I have included [**Speed Estimation**](https://github.com/Asadullah-Dal17/Distance_measurement_using_single_camera/tree/main/Speed) code is well check that out.
+
+:heavy_check_mark: You can find the implementation of [**Distance estimation of multiple objects using Yolo V4**](https://github.com/Asadullah-Dal17/Yolov4-Detector-and-Distance-Estimator) Object Detector Opencv-python
+
+## Clone this Repo:
+
+git clone https://github.com/Asadullah-Dal17/Distance_measurement_using_single_camera
+
+## install Opencv-python
+
+- Windows
+
+ pip install opencv-python
+
+- _install Opencv-python on Linux or Mac_
+
+ pip3 install opencv-python
+
+## Run the code
+
+- windows: :point_down:
+
+ python distance.py
+
+ ------ OR ---------
+
+ python Updated_distance.py
+
+- linux or Mac :point_down:
+
+ python3 distance.py
+
+ ------ OR ---------
+
+ python3 Updated_distance.py
+
+### :bulb:_Focal Length Finder Function Description_ :bulb:
+
+```python
+# focal length finder function
+def focal_length(measured_distance, real_width, width_in_rf_image):
+
+ focal_length_value = (width_in_rf_image * measured_distance) / real_width
+ #return focal length.
+ return focal_length_value
+
+```
+
+The Focal Length finder Function has three Arguments:
+
+`measured_distance` is the distance which we have measured while capturing the reference image:straight*ruler:. \*\*\_From object to Camera*\*\* which is `Known_distance = 72.2 #centimeter`
+
+`real_width` It's measured as the width of the object in the real world, here I measured the width of the face in real-world which was `Known_width =14.3 # centimetre`
+
+`width_in_rf_image` is the width of the object in the image/frame it will be in **pixels**
+
+### :bulb:_Distance Finder Function Description_ :bulb:
+
+```python
+# Distance estimation function
+
+def distance_finder(focal_length, real_face_width, face_width_in_frame):
+
+ distance = (real_face_width * focal_length)/face_width_in_frame
+ return distance
+
+```
+
+This Function takes three Arguments,
+
+` Focal_Length` is the focal length, out of the **FocalLength** finder function.
+
+`real_face_width` measures the width of an object in the real world, here I measured the width of a face in real-world which was `Known_width =14.3 #centimeter`
+
+`face_width_in_frame` is the width of the face in the frame, the unit will be pixels here.
+
+
+
+I have also created Face Following Robot which uses distance Estimation If you are interested you can Watch myYoutube Video
+You can create the following Robot with Raspberry That would be easy then, using Arduino Stuff, Raspberry 🍓 Pi will make it a system on Robot 🤖
+
+If you found this helpful, please star :star: it.
+
+You can Watch my Video Tutorial on Computer Vision Topics, just check out my YouTube Channel
+
+
+## 📫 Let's Connect
+
+
+
+## 💬 Questions or Need Help?
+
+If you have any questions or need help with the project, feel free to DM me on [Instagram](https://www.instagram.com/aiphile17)!
+
+
+
+
+
diff --git a/Raspberry_pi/AiPhile.py b/Raspberry_pi/AiPhile.py
new file mode 100644
index 0000000..cf14ae3
--- /dev/null
+++ b/Raspberry_pi/AiPhile.py
@@ -0,0 +1,53 @@
+import cv2 as cv
+import numpy as np
+# colors
+BLACK = (0,0,0)
+WHITE = (255,255,255)
+BLUE = (255,0,0)
+RED = (0,0,255)
+CYAN = (255,255,0)
+YELLOW =(0,255,255)
+MAGENTA = (255,0,255)
+GREEN = (0,255,0)
+PURPLE = (128,0,128)
+ORANGE = (0,165,255)
+PINK = [147,20,255]
+INDIGO=[75,0,130]
+VIOLET=[238,130,238]
+GRAY=[127,127,127]
+
+def textBG(img, text, position, fonts ,scaling=1, color=(0,255,0), thickness=1, padding=3):
+ img_h, img_w = img.shape[:2]
+ x, y = position
+ (w, h ), p= cv.getTextSize(text, fonts, scaling, thickness)
+ # print(w, h)
+ cv.rectangle(img, (x-p, y+p), (x+w+p, y-h-p), (255, 0,234), -1)
+
+ cv.putText(img, text, position,fonts, scaling, color, thickness)
+
+def textBGoutline(img, text, position, fonts=cv.FONT_HERSHEY_SIMPLEX ,scaling=1, text_color=(0,255,0), thickness=1, bg_color=(BLACK)):
+ img_h, img_w = img.shape[:2]
+ x, y = position
+ (w, h ), p= cv.getTextSize(text, fonts, scaling, thickness)
+ # print(w, h)
+ cv.rectangle(img, (x-p, y+p), (x+w+p, y-h-p), bg_color, -1)
+ cv.rectangle(img, (x-p, y+p), (x+w+p, y-h-p), text_color,thickness, cv.LINE_AA)
+
+ cv.putText(img, text, position,fonts, scaling, text_color, thickness, cv.LINE_AA )
+def fillPolyTrans(img, points, color, opacity, line_thickness=2):
+ """
+ @param img: (mat) input image, where shape is drawn.
+ @param points: list [tuples(int, int) these are the points custom shape,FillPoly
+ @param color: (tuples (int, int, int)
+ @param opacity: it is transparency of image.
+ @return: img(mat) image with rectangle draw.
+
+ """
+ list_to_np_array = np.array(points, dtype=np.int32)
+ overlay = img.copy() # coping the image
+ cv.fillPoly(overlay,[list_to_np_array], color )
+ new_img = cv.addWeighted(overlay, opacity, img, 1 - opacity, 0)
+ # print(points_list)
+ img = new_img
+ cv.polylines(img, [list_to_np_array], True, color,line_thickness, cv.LINE_AA)
+ return img
diff --git a/Raspberry_pi/README.md b/Raspberry_pi/README.md
new file mode 100644
index 0000000..4f0f9f2
--- /dev/null
+++ b/Raspberry_pi/README.md
@@ -0,0 +1,34 @@
+# Run Distance Estimation on Raspberry Pi
+
+## Installation of Opencv-python
+
+```
+sudo apt install ffmpeg python3-opencv
+```
+⚠️ I highly encourage to Build from source, since this module not optimized for Raspberry Pi.
+
+### Install dependency packages
+```
+sudo apt install libxcb-shm0 libcdio-paranoia-dev libsdl2-2.0-0 libxv1 libtheora0 libva-drm2 libva-x11-2 libvdpau1 libharfbuzz0b libbluray2 libatlas-base-dev libhdf5-103 libgtk-3-0 libdc1394-22 libopenexr23
+
+```
+
+## ⚠️ Distance Estimation on Pi Camera
+
+> the distance estimation pi_camera is not tested yet, reason I don't have Pi cam 📷 yet, if you have pi cam try confirm that, I would be greatful, 😄 Thank you so much
+
+I have also create Face Following Robot which use distance Estimation, if you are interested you can Watch myYoutube Video
+You can create Face Following Robot with Raspberry that would be easy then, using Arduino Stuff, Raspberry 🍓 Pi will make it system on Robot 🤖
+
+if You found this Helpful, please star :star: it.
+
+You can Watch my Video Tutorial on Computer Vision Topics, just check out my YouTube Channel
+
+
+If You have any Question or need help in CV Project, Feel free to DM on Instagram
+
+## 💚🖤 Join me on Social Media 🖤💚
+
+