├── README.md ├── .idea ├── .gitignore ├── vcs.xml ├── misc.xml ├── inspectionProfiles │ └── profiles_settings.xml ├── modules.xml └── count_cars.iml ├── cars.jpeg ├── fruit.jpeg ├── sounds └── output.mp3 ├── __pycache__ └── food_facts.cpython-38.pyc ├── food_facts.py └── main.py /README.md: -------------------------------------------------------------------------------- 1 | # object-detection 2 | -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /cars.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kent-Taylor/object-detection/HEAD/cars.jpeg -------------------------------------------------------------------------------- /fruit.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kent-Taylor/object-detection/HEAD/fruit.jpeg -------------------------------------------------------------------------------- /sounds/output.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kent-Taylor/object-detection/HEAD/sounds/output.mp3 -------------------------------------------------------------------------------- /__pycache__/food_facts.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kent-Taylor/object-detection/HEAD/__pycache__/food_facts.cpython-38.pyc -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/count_cars.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /food_facts.py: -------------------------------------------------------------------------------- 1 | import ast 2 | import requests 3 | 4 | def food_facts(food): 5 | 6 | url = "https://calorieninjas.p.rapidapi.com/v1/nutrition" 7 | 8 | querystring = {"query":f"{food}"} 9 | 10 | headers = { 11 | 'x-rapidapi-host': "calorieninjas.p.rapidapi.com", 12 | 'x-rapidapi-key': "7603016162msh8263f88a5aa10dfp18e91ajsna3493aef8fcf" 13 | } 14 | 15 | response = requests.request("GET", url, headers=headers, params=querystring) 16 | 17 | # print(response.text) 18 | 19 | dict_response = ast.literal_eval(response.text) 20 | 21 | # print(dict_response) 22 | 23 | food_facts = { 24 | "saturated fat": dict_response["items"][0]["fat_saturated_g"], 25 | "total fat": dict_response["items"][0]["fat_total_g"], 26 | "carbs": dict_response["items"][0]["carbohydrates_total_g"], 27 | "protein": dict_response["items"][0]["protein_g"], 28 | "sugar": dict_response["items"][0]["sugar_g"], 29 | "sodium": dict_response["items"][0]["sodium_mg"], 30 | "cholesterol": dict_response["items"][0]["cholesterol_mg"] 31 | } 32 | 33 | for key, value in food_facts.items(): 34 | print(f"{key.title()}: {value}") -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | # pip install opencv-contrib-python # some people ask the difference between this and opencv-python 4 | # and opencv-python contains the main packages wheras the other 5 | # contains both main modules and contrib/extra modules 6 | # pip install cvlib # for object detection 7 | 8 | # # pip install gtts 9 | # # pip install playsound 10 | # use `pip3 install PyObjC` if you want playsound to run more efficiently. 11 | 12 | import cv2 13 | import cvlib as cv 14 | from cvlib.object_detection import draw_bbox 15 | from gtts import gTTS 16 | from playsound import playsound 17 | from food_facts import food_facts 18 | 19 | 20 | 21 | 22 | def speech(text): 23 | print(text) 24 | language = "en" 25 | output = gTTS(text=text, lang=language, slow=False) 26 | 27 | output.save("./sounds/output.mp3") 28 | playsound("./sounds/output.mp3") 29 | 30 | 31 | video = cv2.VideoCapture(1) 32 | labels = [] 33 | 34 | while True: 35 | ret, frame = video.read() 36 | # Bounding box. 37 | # the cvlib library has learned some basic objects using object learning 38 | # usually it takes around 800 images for it to learn what a phone is. 39 | bbox, label, conf = cv.detect_common_objects(frame) 40 | 41 | output_image = draw_bbox(frame, bbox, label, conf) 42 | 43 | cv2.imshow("Detection", output_image) 44 | 45 | for item in label: 46 | if item in labels: 47 | pass 48 | else: 49 | labels.append(item) 50 | 51 | if cv2.waitKey(1) & 0xFF == ord("q"): 52 | break 53 | 54 | i = 0 55 | new_sentence = [] 56 | for label in labels: 57 | if i == 0: 58 | new_sentence.append(f"I found a {label}, and, ") 59 | else: 60 | new_sentence.append(f"a {label},") 61 | 62 | i += 1 63 | 64 | speech(" ".join(new_sentence)) 65 | speech("Here are the food facts i found for these items:") 66 | 67 | for label in labels: 68 | try: 69 | print(f"\n\t{label.title()}") 70 | food_facts(label) 71 | 72 | except: 73 | print("No food facts for this item") --------------------------------------------------------------------------------