Commit 38997c3f authored by W.R.Ashini Kaushalya's avatar W.R.Ashini Kaushalya

Inference.ipynb

parent c00d76cf
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
"cells": [ "cells": [
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": 23,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": 24,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -81,7 +81,7 @@ ...@@ -81,7 +81,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": 25,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -131,7 +131,7 @@ ...@@ -131,7 +131,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 4, "execution_count": 26,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -168,8 +168,9 @@ ...@@ -168,8 +168,9 @@
" for box, _, _ in zip(boxes, scores, labels):\n", " for box, _, _ in zip(boxes, scores, labels):\n",
" xmin, ymin, xmax, ymax = box\n", " xmin, ymin, xmax, ymax = box\n",
" roi_item = image_np[int(ymin):int(ymax), int(xmin):int(xmax)]\n", " roi_item = image_np[int(ymin):int(ymax), int(xmin):int(xmax)]\n",
" quality = inference_quality(roi_item)\n",
" item = inference_item(roi_item)\n", " item = inference_item(roi_item)\n",
" quality = inference_quality(roi_item)\n",
"\n",
" output.append({\n", " output.append({\n",
" \"item\": item,\n", " \"item\": item,\n",
" \"quality\": quality,\n", " \"quality\": quality,\n",
...@@ -179,7 +180,7 @@ ...@@ -179,7 +180,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 5, "execution_count": 27,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -189,7 +190,7 @@ ...@@ -189,7 +190,7 @@
" {'item': 'apple', 'quality': 'Rotten'}]" " {'item': 'apple', 'quality': 'Rotten'}]"
] ]
}, },
"execution_count": 5, "execution_count": 27,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
...@@ -201,7 +202,7 @@ ...@@ -201,7 +202,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 6, "execution_count": 28,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -212,7 +213,7 @@ ...@@ -212,7 +213,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 16, "execution_count": 29,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -231,7 +232,7 @@ ...@@ -231,7 +232,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 40, "execution_count": 30,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -278,9 +279,61 @@ ...@@ -278,9 +279,61 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 31,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [
"# while True:\n",
"# if ref_node_cart.get() is not None:\n",
"# data_cart = ref_node_cart.get()\n",
"# print(data_cart)\n",
"# data_cart = data_cart['products']\n",
"# data_cart = list(data_cart.values())\n",
" \n",
"# cart_details = {}\n",
"# for item in data_cart:\n",
"# item_name = item['name'].strip().lower()\n",
"# quantity = item['qty']\n",
"\n",
"# if item_name not in cart_details:\n",
"# cart_details[item_name] = quantity\n",
"\n",
"# cap = cv.VideoCapture(0)\n",
"# while True:\n",
"# cart_details_cp = cart_details.copy() \n",
"# for i in range(cart_details_cp[item]):\n",
"# while cart_details_cp[item] > 0:\n",
"\n",
"# break \n"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {},
"outputs": [],
"source": [
"import cv2\n",
"from matplotlib import pyplot as plt"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'apple': 3, 'grape': 1}\n",
"selected apple is Fresh\n",
"selected apple is Fresh\n",
"selected grape is Fresh\n",
"selected grape is Fresh\n"
]
}
],
"source": [ "source": [
"while True:\n", "while True:\n",
" if ref_node_cart.get() is not None:\n", " if ref_node_cart.get() is not None:\n",
...@@ -295,43 +348,75 @@ ...@@ -295,43 +348,75 @@
"\n", "\n",
" if item_name not in cart_details:\n", " if item_name not in cart_details:\n",
" cart_details[item_name] = quantity\n", " cart_details[item_name] = quantity\n",
"\n", " print(cart_details)\n",
" cap = cv.VideoCapture(0)\n", " cap = cv.VideoCapture(0)\n",
" while True:\n", " while True:\n",
" cart_details_cp = cart_details.copy()\n", " cart_details_cp = cart_details.copy()\n",
" for i in range(quantity):\n", " for item, quantity in cart_details_cp.items():\n",
" while cart_details_cp[item] > 0:\n", " for i in range(cart_details_cp[item]):\n",
"\n", " while cart_details_cp[item] > 0:\n",
" image = cap.read()[1]\n", "\n",
" image = cv.cvtColor(image, cv.COLOR_BGR2RGB)\n", " image = cap.read()[1]\n",
" cv.imwrite('tmp.jpg', image)\n", " # image = cv.cvtColor(image, cv.COLOR_BGR2RGB)\n",
"\n", " cv.imwrite('tmp.jpg', image)\n",
" output = process_objects('tmp.jpg')\n", "\n",
"\n", " # plt.imshow(image)\n",
" if len(output) > 0:\n", " # plt.show() \n",
" for o in output:\n", "\n",
" item = o['item']\n", " cv2.imshow(\"CART\", image)\n",
" quality = o['quality']\n", "\n",
" if quality == \"Fresh\":\n", " k = cv2.waitKey(1)\n",
" cart_details_cp[item] -= 1\n", " if k%256 == 27:\n",
" speech_string = f\"selected {item} is {quality}\"\n", " print(\"Escape hit, closing...\")\n",
" print(speech_string)\n", " break \n",
"\n", "\n",
" # update speech in ref_node_blind_voice node\n", " try:\n",
" ref_node_blind_voice.update({\n", " output = process_objects('tmp.jpg')\n",
" 'speech': speech_string,\n", " except:\n",
" 'location' : ref_node_blind_voice.get()['location']\n", " pass\n",
" })\n", "\n",
" if len(output) > 0:\n",
" for o in output:\n",
" item_det = o['item']\n",
" quality_det = o['quality']\n",
" \n",
" if item_det in cart_details_cp:\n",
" if quality_det == \"Fresh\":\n",
" cart_details_cp[item] -= 1\n",
" speech_string = f\"selected {item_det} is {quality_det}\"\n",
" print(speech_string)\n",
"\n",
" # update speech in ref_node_blind_voice node\n",
" ref_node_blind_voice.update({\n",
" 'speech': speech_string,\n",
" 'location' : ref_node_blind_voice.get()['location']\n",
" })\n",
" \n", " \n",
"\n", "\n",
" for item, quantity in cart_details_cp.items(): \n", " for item, quantity in cart_details_cp.items(): \n",
" if quantity == 0:\n", " if quantity == 0:\n",
" del cart_details_cp[item]\n", " del cart_details[item]\n",
"\n", "\n",
" if len(cart_details_cp) == 0:\n", " if len(cart_details) == 0:\n",
" ref_node_cart.delete()\n", " ref_node_cart.delete()\n",
" break" " break\n",
"\n",
" cv2.destroyAllWindows()"
] ]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
} }
], ],
"metadata": { "metadata": {
...@@ -350,7 +435,7 @@ ...@@ -350,7 +435,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.8.13" "version": "3.8.17"
}, },
"orig_nbformat": 4 "orig_nbformat": 4
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment