Git Product home page Git Product logo

paul-pias / object-detection-and-distance-measurement Goto Github PK

View Code? Open in Web Editor NEW
318.0 9.0 112.0 153 KB

Using yolov3 & yolov4 weights objects are being detected from live video frame along with the measurement of the object from the camera without the support of any extra hardware device.

Python 97.02% HTML 2.98%
distance-measurement-using-camera real-time-distance-measurement object-distance-using-camera object-detection-using-yolov3 real-time-object-detection yolov3 video-object-detection webcam-object-detection yolov4

object-detection-and-distance-measurement's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

object-detection-and-distance-measurement's Issues

Using in ubuntu

Hi every one,

How can I use this code in Ubuntu? When I used it, I got these errors:

me@me:~/Object-Detection-and-Distance-Measurement/YOLOv4$ python3 app.py
Traceback (most recent call last):
File "app.py", line 5, in
from camera import ObjectDetection
File "/home/me/Object-Detection-and-Distance-Measurement/YOLOv4/camera.py", line 9, in
from darknet import Darknet
File "/home/me/Object-Detection-and-Distance-Measurement/YOLOv4/darknet.py", line 4, in
from tool.region_loss import RegionLoss
File "/home/me/Object-Detection-and-Distance-Measurement/YOLOv4/tool/region_loss.py", line 3, in
from tool.torch_utils import *
File "/home/me/Object-Detection-and-Distance-Measurement/YOLOv4/tool/torch_utils.py", line 13, in
from tool import utils
File "/home/me/Object-Detection-and-Distance-Measurement/YOLOv4/tool/utils.py", line 11, in
import win32com.client as wincl #### Python's Text-to-speech (tts) engine for windows, multiprocessing
ModuleNotFoundError: No module named 'win32com'

how to implement to tiny yolo voc?

Hello there @paul-pias

This code is very interesting, any clue on how to implement object detection and distance measurement for yolotinyvoc, which i use with darkflow. Any suggestion?
Thanks in advance

Distance measurment

Hello, actually i've tried using the distance measurement but it dosen't work all the time , it sometimes count the objects in the video and speaks the kind of the objects but it dosen't tell the distance always.
Thank you :)

Generalization of the formula

Hello,
Thank you for sharing this project.
Sorry, how did you get this formula:?
distancei = (2 x 3.14 x 180) ÷ (w + h x 360) x 1000 + 3
I didn't quite understand. Are we supposed to know the real object size ?
Please I want to use this formula in my own Android application and I didn't quite understand how?
Can you please make it more general?
I have to detect the focal length and then what other parameters?
Thanks in advance

Issues with the weight

I find that the weights of the project is saved in yolov3.weights. But the weights gotten from the file only has 28 elements. And it makes the whole project fail to run. How to solve this problem

Thank you for reaching out!

Thank you for reaching out!
You can use espeak instead of win32com.

First, try to install using the following command from your terminal.

  • sudo apt-get install espeak python3-espeak

Then import in the object_detection.py script

  • from espeak import espeak

and replace the #244 line with

  • espeak.synth(feedback)

I hope it will resolve the issue. Kindly let me know if it works or not.

Originally posted by @paul-pias in #2 (comment)

Raspberry Pi OS to be Used

@paul-pias
Hello mate! I'm confused whether I should install a 32 or 64 bit OS in Rpi4. I know 64 bit is needed for pytorch installation but then the 64 bit beta os does not work well when using the camera. Can you help me on what to install?

Compatibility issues with Ubuntu while using tts engine for windows

How can I run the project in Ubuntu since the object_detection.py file uses windows "win32com.client" for windows. Is there any alternative tts engine for ubuntu or is it only compatible with windows os.

The error is as follows:
import win32com.client as wincl Traceback (most recent call last): File "object_detection.py", line 18, in <module> import win32com.client as wincl ImportError: No module named 'win32com'

RuntimeError: typeerror: expected PRT <cv::umat> for argument 'src'

Hi,
When I tried to run the code "object_detection.py" for a video. I am able to read the video, resize it. There was a error:
TypeError: Expected cv::UMat for argument 'src', line:"frame = cv2.resize(frame,(self.width, self.height))"

I am using opencv 4.2.0 on python 3.7. I guess it may be because of version. Which Pytorch Version you are using? Thanks!

Input frame size for getting the distance result.

I was trying to find the distance of the bounding boxes. What exactly should be the frame size for the formula to work.
you have mentioned 640*480 and getting the bounding boxes and passing the (w,h)
coordinates. I am not getting the results. Can you suggest to replicate the result?

Platform dependent

The library you used "pywin32" can only be used for windows.

  • Find an alternative for the respective library for Linux .

new issue found on rpi

python3.5 /home/pi/o/object_detection.py
Traceback (most recent call last):
File "/home/pi/o/object_detection.py", line 159, in
ObjectDetection(id).main()
File "/home/pi/o/object_detection.py", line 89, in init
self.classes = load_classes('data/coco.names')
File "/home/pi/o/util.py", line 81, in load_classes
fp = open(namesfile, "r")
FileNotFoundError: [Errno 2] No such file or directory: 'data/coco.names'

Download of videos

Hi everyone,

Could you upload the videos in other source please? Because unfortunately I got this error from git lfs.

response: This repository is over its data quota. Account responsible for LFS bandwidth should purchase more data packs to restore access.

Thanks in advance

!ssize.empty() in function 'cv::resize'

Hello,
Anyone came across the above mentioned problem?? When I choose to load a video , I get this error.
However i cant locate the file because the folder it is supposed to be in (opencv-python\opencv\modules\imgproc\src\resize.cpp) does not exist in the specific path ( C:\projects).
I have installed opencv-python using pip install.
Any ideas?

Use with model based on ssd_mobilnet dataset?

Hi @paul-pias

Is it possible to execute your script with a model that was trained with TensorFlow and the "ssd_mobilenet_v2_quantized_coco" dataset? The format of the model is .pb as well. I tried it by changing the path to the model and the labelmap in your "objDet_utils.py" script(line 15 and 18). But I get a "NoneType: none" exception in line 102 of your "object_detection.py" script. I would be very grateful for your help! (I'm using my webcam, so changed id to 0)

OS: Windows 10
TF: 1.15.0
Python: 3.5.5

distance measurement

I wonder how this {d = f + R/r} formula came out.
Does d mean do? Or does it mean oblique distance?

Visual output of the code

Hi everyone,
I was wondering if there is an optical output after we run the code.
E.g a video that is the same with the original plus bounding boxes and markers that mark the distance
Or more generally, where can we see the distance information?

Distance calculation

Thanks for the code, Paul!
Your calculation of the distance is impressing and the description is very clear. However, I think it applies to the objects those are facing the camera directly or near direct facing the camera. If an object is distorted a lot in the image, for example, the objects from a CCTV camera, where the image covers a wide range of areas, the calculation may not be applied. In that case, maybe we should use perspective transform and wrapping before applying your method? Any suggestion?

Video is displayed without detection

Hello @paul-pias ,
Thank you for sharing your code.

I'm trying to run the code on a video file using cv.VideoCapture() and (ret,frame), the video is displayed as it is without object detection nor distance measurement.
What am i missing here?

Wrong output rpi

the output has no detection as you can see

python3.5 /home/pi/o/object_detection.py
Loading network.....
Network successfully loaded
[INFO] elasped time: 4.74
[INFO] approx. FPS: 0.2
[INFO] elasped time: 4.41
[INFO] approx. FPS: 0.2
[INFO] elasped time: 4.45
[INFO] approx. FPS: 0.2
[INFO] elasped time: 5.33
[INFO] approx. FPS: 0.2
[INFO] elasped time: 4.46
[INFO] approx. FPS: 0.2
[INFO] elasped time: 4.11
[INFO] approx. FPS: 0.2
[INFO] elasped time: 4.89
[INFO] approx. FPS: 0.2
[INFO] elasped time: 4.57
[INFO] approx. FPS: 0.2
[INFO] elasped time: 8.39
[INFO] approx. FPS: 0.1
[INFO] elasped time: 7.41
[INFO] approx. FPS: 0.1

Doubt regarding the distance estimation

The formula for the distance estimation is mentioned as distancei = (2 x 3.14 x 180) ÷ (w + h x 360) x 1000 + 3. I have a counterexample in mind. Please let me know if I have made a mistake. Suppose you take two objects, one much larger than the other. Place the smaller object close to the camera and the larger object far away from the camera while ensuring the fact that both the objects take up the same bounding box space in the camera. In this case, the distance estimate will be the same for both objects when one of them is in fact much farther than the other.

video output related

i was testing your code, the program is taking the video input from my webcam but the bounding boxes and the distances are not being displayed. i have downloaded the updated version of this repo..also gone through the other issues regarding the video output issue..
i have used this line ==>frame = cv2.putText(frame, str("{:.2f} Inches".format(distance)), (w,h), cv2.FONT_HERSHEY_DUPLEX, 0.6, (0,0,255), 1, cv2.LINE_AA) and initialized the distance variable..but still the bounding boxes and the distance is not being show and called out..

NEED HELP

Can you help me in running this project from starting. I am getting stuck.

!ssize.empty()

error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize'
whan should I do?

Field of View

Does this program consider the field of view and the altitude of the camera?

No detection taking place using WebCam

Installed all the packages needed to run the code. It ran successfully without any glitch but there's no object detection and distance measurement taking place. I have used both Webcam and video files but nothing.

Can we schedule a 10min meet to resolve it?

distance_measurement

hello, please help to understand equations for distance estimation
i want to use this part in my project
1-i donot understand third equation d=f+R/r what you mean is d==do((Distance of object from the lens)? is R height in image , r height in real?
2-how you get focal length formula?
3-how you get relation distance from w , h as I use images with size 600*800
4- if there any specs of camera

Nvidia nano

Can i use NVIDIA Jetson nano for this project? And if yes , what are the requirements and the changes for this repo?
Thank you in advance.

About diatance measurement

Hello.It's a great job.I ran this code, but the distance measurement doesn't work, there is a big error, I don't know how to fix it.
Thanks.

RuntimeError: "clamp_cpu" not implemented for 'Half'

Hi

I have just started implementing it. Trying to run the code "object_detection.py" for a video. I am able to read the video, resize it, as is inside the code. Although I am getting the following error:

Traceback (most recent call last): File "object_detection.py", line 141, in <module> ObjectDetection(id).main() File "object_detection.py", line 110, in main output[:,1:5] = torch.clamp(output[:,1:5], 0.0, float(self.inp_dim))/self.inp_dim RuntimeError: "clamp_cpu" not implemented for 'Half'

When I commented out the line

output = output.type(torch.half)

it works and does detection. But I am not sure if that's the right way to resolve the error. Please guide as what would be the issue. Thanks!

I wanted to add text-to-speech to YoloV4

I run Yolov4 code. It run perfectly but I wanted to add speech that says like "person at 20 inches" but I couldn't because I couldn't find where is distance variable. In Yolov3 code, there is distance variable but in Yolov4, I couldn't find it.

Some confusion about distance measurement

Thank you for your outstanding contribution, but I have some confusion about distance measurement:
(1) According to the formula: distancei = (2 x 3.14 x 180) ÷ (w + hx 360) x 1000 + 3, if the same person is detected, it is obvious that the w, h of the bbox of the face is much smaller than that of the pedestrian bbox, according to the formula, the calculated distancei of the face is much farther than the pedestrian, but they belong to the same person at the same depth. The calculated result does not seem to be in accordance with common sense. Does the formula have any restrictions?
(2) How is the formula d = f + R / r inferred?
(3) Why is focal length a constant? (f=2x3.14x180/360)
Thank you very much for your enthusiastic answer!

Use EfficientDet Network

Hi,

Is it possible to change the current Yolo model for EfficientDet? I can improve this repo using another model, could you guide me for this update, please?

I take [Errno 2] No such file or directory: 'yolov4.weights'

In order to solve this error, I downloaded yolov4.weights and put under "YOLOv4" file but I get different error (error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize'). How can I solve this error?

I downloaded YOLOv3 and YOLOv4 weights from links you shared (YOLOv3 YOLOv4 ) and I put them under "YOLOv4" file both. 5 file had same name. I changed them with original files. Entire error:

Traceback (most recent call last):
  File "C:\Users\Ahmet\anaconda3\envs\yolou4\lib\threading.py", line 926, in _bootstrap_inner
    self.run()
  File "C:\Users\Ahmet\anaconda3\envs\yolou4\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\Ahmet\Desktop\Object Detection Projeler\Object-Detection-and-Distance-Measurement\YOLOv4\object_detection.py", line 84, in frame_render
    frame = cv2.resize(frame,(self.width, self.height))
cv2.error: OpenCV(4.5.2) C:\Users\runneradmin\AppData\Local\Temp\pip-req-build-dn5w5exm\opencv\modules\imgproc\src\resize.cpp:4051: error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize'

issues reg opencv accessing webcam on windows 10

[ WARN:[email protected]] global D:\a\opencv-python\opencv-python\opencv\modules\videoio\src\cap_msmf.cpp (1752) CvCapture_MSMF::grabFrame videoio(MSMF): can't grab frame. Error: -1072875772

hello , i am trying to run the file object_detection.py and i am getting this same error over and over , it worked perfectly fine before 2 months, but i had to delete all the files , when i tried to reinstall all the requirements and run i am getting these , i searched the stack overflow couldnt find anything helpful , i set the id val=0 to run on webcam locally . Can you please tell me why i am getting this error .
Thanks in advance.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.