paul-pias / Object-Detection-and-Distance-Measurement

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.
348 stars 118 forks source link

Doubt regarding raspberry pi model #15

Closed ghost closed 4 years ago

ghost commented 4 years ago

I have to use the webcam now and raspberry pi later, what else changes do I need to make in the code for both.

ghost commented 4 years ago

Hello ,I m getting error in line 125 of object_detection.py saying "local varibale 'distance ' referred before assignment" What should I do to solve this error bcz distance vairable is already used to calculate the distance in inches?

paul-pias commented 4 years ago

Maybe the issue is regarding global and local scope. Anyway, you can declare the variable at the model initialization as self.distance = 0.0 in line 80 of object_detection.py and replace the distance variable at line 115 and 125 with self.distance as follows.

self.distance = (2 3.14 180) / (w + h 360) 1000 + 3

frame = cv2.putText(frame, str("{:.2f} Inches".format(self.distance)), (x,y), cv2.FONT_HERSHEY_DUPLEX, 0.6, (0,0,255), 1, cv2.LINE_AA)

I hope, it will resolve your problem.

ghost commented 4 years ago

I tried doing it.But then the same problem arises for the vairable 'x' (in the same line)

paul-pias commented 4 years ago

May I know which IDE you are using to edit the code. Did you change anything in the code or you are running as it is? Kindly only download the object_detection.py again and try adding distance=0.0 in line 30.

ghost commented 4 years ago

I am using spyder (annacond3.7). I had downloaded the entire zip file and tried running object_detection.py .After doing this the error of distance occured.Replaced distance with self.distance and then the error of x occured. How would the look output look like?Do you have any set of outputs?Because when I replaced x and y variables the same way(self.x and self.y) webcam opened up but the distance wasnt shown anywhere

paul-pias commented 4 years ago

The output will look like this. https://bit.ly/3f5puYq And I updated the object_detection.py as there were few variables sharing the same name which was causing local/global scope declaration issues. Check if it works for you now.

ghost commented 4 years ago

There is no as such error now .Thanks for it.But when tried running the object_detection.py file it shows only the time elapsed and aprrxo FPS and nothing else.Neither showing the distance of object from camera..Can u please help me with this?

paul-pias commented 4 years ago

Kindly print your necessary variable according to your need.

paul-pias commented 4 years ago

These are basic programming questions. Why would you print cv2.puttext? cv2.puttext is not a statement, it's a method/ function, you can see this for reference. However, you can print the distance variable inside the write method. Anyway, I think you can debug the code line by line for a better understanding. Thank you.