Doubt regarding raspberry pi model
Opened this issue · 9 comments
I have to use the webcam now and raspberry pi later, what else changes do I need to make in the code for both.
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?
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.
I tried doing it.But then the same problem arises for the vairable 'x' (in the same line)
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.
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
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.
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?
Kindly print your necessary variable according to your need.
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.