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

Inference.ipynb

parent c00d76cf
......@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 23,
"metadata": {},
"outputs": [],
"source": [
......@@ -19,7 +19,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 24,
"metadata": {},
"outputs": [
{
......@@ -81,7 +81,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 25,
"metadata": {},
"outputs": [],
"source": [
......@@ -131,7 +131,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 26,
"metadata": {},
"outputs": [],
"source": [
......@@ -168,8 +168,9 @@
" for box, _, _ in zip(boxes, scores, labels):\n",
" xmin, ymin, xmax, ymax = box\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",
" quality = inference_quality(roi_item)\n",
"\n",
" output.append({\n",
" \"item\": item,\n",
" \"quality\": quality,\n",
......@@ -179,7 +180,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 27,
"metadata": {},
"outputs": [
{
......@@ -189,7 +190,7 @@
" {'item': 'apple', 'quality': 'Rotten'}]"
]
},
"execution_count": 5,
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
......@@ -201,7 +202,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 28,
"metadata": {},
"outputs": [],
"source": [
......@@ -212,7 +213,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 29,
"metadata": {},
"outputs": [],
"source": [
......@@ -231,7 +232,7 @@
},
{
"cell_type": "code",
"execution_count": 40,
"execution_count": 30,
"metadata": {},
"outputs": [],
"source": [
......@@ -278,9 +279,61 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 31,
"metadata": {},
"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": [
"while True:\n",
" if ref_node_cart.get() is not None:\n",
......@@ -295,26 +348,42 @@
"\n",
" if item_name not in cart_details:\n",
" cart_details[item_name] = quantity\n",
"\n",
" print(cart_details)\n",
" cap = cv.VideoCapture(0)\n",
" while True:\n",
" cart_details_cp = cart_details.copy()\n",
" for i in range(quantity):\n",
" for item, quantity in cart_details_cp.items():\n",
" for i in range(cart_details_cp[item]):\n",
" while cart_details_cp[item] > 0:\n",
"\n",
" image = cap.read()[1]\n",
" image = cv.cvtColor(image, cv.COLOR_BGR2RGB)\n",
" # image = cv.cvtColor(image, cv.COLOR_BGR2RGB)\n",
" cv.imwrite('tmp.jpg', image)\n",
"\n",
" # plt.imshow(image)\n",
" # plt.show() \n",
"\n",
" cv2.imshow(\"CART\", image)\n",
"\n",
" k = cv2.waitKey(1)\n",
" if k%256 == 27:\n",
" print(\"Escape hit, closing...\")\n",
" break \n",
"\n",
" try:\n",
" output = process_objects('tmp.jpg')\n",
" except:\n",
" pass\n",
"\n",
" if len(output) > 0:\n",
" for o in output:\n",
" item = o['item']\n",
" quality = o['quality']\n",
" if quality == \"Fresh\":\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} is {quality}\"\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",
......@@ -326,12 +395,28 @@
"\n",
" for item, quantity in cart_details_cp.items(): \n",
" if quantity == 0:\n",
" del cart_details_cp[item]\n",
" del cart_details[item]\n",
"\n",
" if len(cart_details_cp) == 0:\n",
" if len(cart_details) == 0:\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": {
......@@ -350,7 +435,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.13"
"version": "3.8.17"
},
"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