Commit
·
ea488fc
1
Parent(s):
dfb7e1f
Image recognition
Browse files- captured_image.jpg +0 -0
- index.py +19 -27
captured_image.jpg
ADDED
|
index.py
CHANGED
|
@@ -1,76 +1,68 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import cv2
|
| 3 |
-
|
| 4 |
-
|
| 5 |
def main():
|
| 6 |
st.title('NouriScan')
|
| 7 |
|
| 8 |
st.sidebar.header('Ingredients & Nutrition')
|
| 9 |
|
| 10 |
-
|
| 11 |
option1 = st.sidebar.checkbox('Banana')
|
| 12 |
option2 = st.sidebar.checkbox('Strawberry')
|
| 13 |
option3 = st.sidebar.checkbox('Kale')
|
| 14 |
option4 = st.sidebar.checkbox('Orange Juice')
|
| 15 |
option5 = st.sidebar.checkbox('Almond Milk')
|
|
|
|
| 16 |
button_clicked = st.sidebar.button('Done')
|
|
|
|
| 17 |
if not button_clicked:
|
| 18 |
videoCapture()
|
| 19 |
-
|
| 20 |
displayRecipes()
|
| 21 |
|
| 22 |
def displayRecipes():
|
| 23 |
items = [
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
]
|
| 28 |
|
| 29 |
-
# Display the items with expanding boxes
|
| 30 |
for item in items:
|
| 31 |
with st.expander(item["title"]):
|
| 32 |
st.write(item["content"])
|
| 33 |
|
| 34 |
-
|
| 35 |
-
|
| 36 |
def videoCapture():
|
| 37 |
-
|
| 38 |
-
# Create a VideoCapture object to access the webcam
|
| 39 |
cap = cv2.VideoCapture(0)
|
| 40 |
-
|
| 41 |
-
# Set the video frame width and height (optional)
|
| 42 |
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
|
| 43 |
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)
|
| 44 |
|
| 45 |
-
# Check if the webcam is opened correctly
|
| 46 |
if not cap.isOpened():
|
| 47 |
st.error("Error: Unable to access the webcam.")
|
| 48 |
return
|
| 49 |
|
|
|
|
|
|
|
| 50 |
# Display a placeholder for the video stream
|
| 51 |
video_placeholder = st.empty()
|
| 52 |
|
| 53 |
-
|
| 54 |
# Read a frame from the webcam
|
| 55 |
ret, frame = cap.read()
|
| 56 |
|
| 57 |
if not ret:
|
| 58 |
st.error("Error: Unable to read frame from the webcam.")
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
|
|
|
| 63 |
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
break
|
| 67 |
|
| 68 |
# Release the VideoCapture and close the OpenCV window
|
| 69 |
cap.release()
|
| 70 |
cv2.destroyAllWindows()
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
|
| 75 |
if __name__ == '__main__':
|
| 76 |
-
main()
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import cv2
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
def main():
|
| 6 |
st.title('NouriScan')
|
| 7 |
|
| 8 |
st.sidebar.header('Ingredients & Nutrition')
|
| 9 |
|
|
|
|
| 10 |
option1 = st.sidebar.checkbox('Banana')
|
| 11 |
option2 = st.sidebar.checkbox('Strawberry')
|
| 12 |
option3 = st.sidebar.checkbox('Kale')
|
| 13 |
option4 = st.sidebar.checkbox('Orange Juice')
|
| 14 |
option5 = st.sidebar.checkbox('Almond Milk')
|
| 15 |
+
|
| 16 |
button_clicked = st.sidebar.button('Done')
|
| 17 |
+
|
| 18 |
if not button_clicked:
|
| 19 |
videoCapture()
|
| 20 |
+
else:
|
| 21 |
displayRecipes()
|
| 22 |
|
| 23 |
def displayRecipes():
|
| 24 |
items = [
|
| 25 |
+
{"title": "Item 1", "content": "Content for Item 1."},
|
| 26 |
+
{"title": "Item 2", "content": "Content for Item 2."},
|
| 27 |
+
{"title": "Item 3", "content": "Content for Item 3."}
|
| 28 |
]
|
| 29 |
|
|
|
|
| 30 |
for item in items:
|
| 31 |
with st.expander(item["title"]):
|
| 32 |
st.write(item["content"])
|
| 33 |
|
|
|
|
|
|
|
| 34 |
def videoCapture():
|
|
|
|
|
|
|
| 35 |
cap = cv2.VideoCapture(0)
|
|
|
|
|
|
|
| 36 |
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
|
| 37 |
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)
|
| 38 |
|
|
|
|
| 39 |
if not cap.isOpened():
|
| 40 |
st.error("Error: Unable to access the webcam.")
|
| 41 |
return
|
| 42 |
|
| 43 |
+
st.write("Click 'Capture Image' to capture an image.")
|
| 44 |
+
|
| 45 |
# Display a placeholder for the video stream
|
| 46 |
video_placeholder = st.empty()
|
| 47 |
|
| 48 |
+
if st.button("Capture Image"):
|
| 49 |
# Read a frame from the webcam
|
| 50 |
ret, frame = cap.read()
|
| 51 |
|
| 52 |
if not ret:
|
| 53 |
st.error("Error: Unable to read frame from the webcam.")
|
| 54 |
+
else:
|
| 55 |
+
# Save the captured frame as an image
|
| 56 |
+
image_path = "captured_image.jpg"
|
| 57 |
+
cv2.imwrite(image_path, cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))
|
| 58 |
+
st.write("Image captured and saved as", image_path)
|
| 59 |
|
| 60 |
+
# Display the captured image
|
| 61 |
+
st.image(image_path, use_column_width=True)
|
|
|
|
| 62 |
|
| 63 |
# Release the VideoCapture and close the OpenCV window
|
| 64 |
cap.release()
|
| 65 |
cv2.destroyAllWindows()
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
if __name__ == '__main__':
|
| 68 |
+
main()
|