wk-labs/lab2.ipynb

281 lines
395 KiB
Plaintext
Raw Normal View History

2021-11-23 21:40:19 +01:00
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "637b3ea7",
"metadata": {},
"outputs": [],
"source": [
"import cv2 as cv\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "e78bd13a",
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAPUAAAD4CAYAAAA0L6C7AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuNCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8QVMy6AAAACXBIWXMAAAsTAAALEwEAmpwYAAAKgUlEQVR4nO3d3Ytc9R3H8c/HTUTrA16Yis2GqiDeeGHMEigBaVOVtIr2ohcKeiGF3FSJtCBaKMV/QPSqIJrW4kMQNSDS+gAarFCjWR+qMSohWFxiiWJF04uK+ulFjmW1m+zZmTlnJt95v2DJTnZ2fr9N8s45Z2bO+TmJANRxwrgnAGC0iBoohqiBYogaKIaogWJWdfGgtnlKvWcbNmwY6/jz8/NjHX8aJfFSv+8uXtIi6v6N+6VJe8l/X+jQ0aJm9xsohqiBYogaKIaogWKIGiiGqIFiiBoohqiBYogaKIaogWKIGiimVdS2t9h+x/Z+27d2PSkAg1v2hA7bM5LelXSZpAVJL0u6Nslbx/geTujoGSd0TJ9hTujYKGl/kgNJPpe0Q9LVo5wcgNFpE/VaSe8vur3Q/N432N5qe4/tPaOaHICVa3ORhKU28f+3r5fkbkl3S+x+A+PUZku9IGndotuzkg52Mx0Aw2oT9cuSzrd9ru0TJV0j6fFupwVgUMvufif5wvaNkp6SNCNpe5K9nc8MwEC4RlkRvKQ1fbhGGTAliBoohqiBYogaKIaogWKIGiiGqIFiiBoohqiBYjpZynacxv3Oqmk1rX/uk/hOOrbUQDFEDRRD1EAxRA0UQ9RAMUQNFEPUQDFEDRRD1EAxRA0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2sp5/bkk5Jctj2akkvSNqW5MWux140h19JmpN0epIrexz3PUlzSXp/84nt+yT9Nck9Xy9jleSTUT3+JG2pN0ran+RAks8l7ZB0dR8DJ3le0sd9jLXE2B8keaX5/DNJ+ySt7WnsJDnc3FzdfPT2v7ztWUlX6MiVaqdCs4zVJZLulaQkn48yaGmyol4r6f1FtxfU0z/uSWH7HEnrJe1e5q6jHHPG9muSDkl6ZtGiDX24U9Itkr7qccyvRdLTtudtb+1x3FbLWA1jkqJe6s3Lk3Fs0APbp0p6VNLNST7ta9wkXya5SNKspI22ezn8sH2lpENJ5vsYbwmbklws6SeSftkcgvVhlY6scPP7JOsl/VvSSJ8/mqSoFyStW3R7VtLBMc2lV83x7KOSHkjy2Djm0OwC7pK0pachN0m6qjm23SFps+37expbSQ42vx6StFNHDv/60PkyVpMU9cuSzrd9bvPkwTWSHh/znDrXPFl1r6R9Se7oeew1ts9oPj9Z0qWS3u5j7CS3JZlNco6O/F0/m+S6Psa2fUrzpKSaXd/LJfXyykcfy1h1derliiX5wvaNkp6SNCNpe5K9fYxt+yFJP5R0pu0FSb9Lcm8fY+vIFut6SW80x7aS9Jskf+5h7LMl3de88nCCpIeT9PrS0picJWlnc7rqKkkPJnmyx/FvkvRAs/E6IOmGUT74xLykBWA0Jmn3G8AIEDVQDFEDxRA1UAxRA8UQNVAMUQPF/BdF7wZviuJ+ZQAAAABJRU5ErkJggg==\n",
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"kernel_ellipse = cv.getStructuringElement(cv.MORPH_ELLIPSE, (7, 7))\n",
"plt.imshow(kernel_ellipse, cmap='gray');"
]
},
{
"cell_type": "code",
"execution_count": 200,
"id": "453c5a62",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Text(0.5, 1.0, 'Final')"
]
},
"execution_count": 200,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANS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PZ2ZmUlBT8/PyYPn06a9asQaVSYTabueeee1AoFBiNRiRJorKykj179jBy5Ejq6+tZt24der2erKwsysrKWL58OX5+fkRFRREeHk6XLl1YsWIFHTp0wGQyERwczOjRo6moqKCwsJC+ffuSlpbGyZMn0Wg0dOjQgb59+7J37172799PSUkJvXr14ptvviEwMJCoqCjuuOMOJk2aRHR0NFVVVdTU1DB27Fh27NjBkSNHGDNmDJ999hkvv/xysylSGZlzuR79dTkyMzM5duwYEydObIrhbmscHR1Rq9WNjgkhyM3NbTZdYW9vj7u7e7OMLXN70GzOUEKIzUKIjkKI9kKIT662f15eHmvWrGHBggW89tprrF69miNHjvDoo48yc+ZMNm/ezH//+19OnTrFDz/8wL333ovBYKC+vp727dsTHBzMpk2bGDp0KEajEbPZzF133cX8+fOJiYmhc+fOeHt7c//999OmTRt++OEHkpOT6d+/PxkZGWzbtg04s+W2ZMkSOnfuzIABAxrJ6O3tTVFREba2tjz00EMkJiby9ddfExoayqZNm6ivr+cf//gHp06dolOnTjg6OmJjY8OXX35JaGgo6enprFq1ij59+rB69Wqio6PR6/UYjUbGjRvHr7/+ypEjRxrNaWdnh52dHYcPn1/j2c3NjZCQEDZt2kSPHj0wm80UFhYyatQoYmNj2b59OwA2NjaMHTuW+vp6vvjiCxISEvjXv/7Fr7/+Cpzx69q8eTNdunTBx8eHHTt2MHToUNq3b8/GjRuJiIjgvvvuY968ecTHx+Pi4sKOHTsoLi7
"text/plain": [
"<Figure size 720x576 with 4 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"#Zad.1\n",
"text = cv.imread(\"img/text_no_ocr.png\", cv.IMREAD_GRAYSCALE)\n",
"_, text_bin = cv.threshold(text, 100, 255, cv.THRESH_BINARY)\n",
"\n",
"kernel_ellipse = cv.getStructuringElement(cv.MORPH_ELLIPSE, (5, 5))\n",
"\n",
"text_dilated = cv.dilate(text_bin, kernel_ellipse, iterations=1)\n",
"\n",
"text_eroded = cv.erode(text_dilated, kernel_ellipse, iterations=1)\n",
"\n",
"final_img = text_bin - text_eroded\n",
"final_img = cv.bitwise_not(final_img)\n",
"\n",
"\n",
"plt.figure(figsize=[10,8])\n",
"plt.subplot(221)\n",
"plt.imshow(text_bin, cmap='gray')\n",
"plt.title(\"Binary\")\n",
"plt.subplot(222)\n",
"plt.imshow(text_dilated, cmap='gray')\n",
"plt.title(\"Dilated\")\n",
"plt.subplot(223)\n",
"plt.imshow(text_eroded, cmap='gray')\n",
"plt.title(\"Eroded\")\n",
"plt.subplot(224)\n",
"plt.imshow(final_img, cmap='gray')\n",
"plt.title(\"Final\")"
]
},
{
"cell_type": "code",
"execution_count": 201,
"id": "6119e7d0",
"metadata": {},
"outputs": [],
"source": [
"#zad.2"
]
},
{
"cell_type": "code",
"execution_count": 202,
"id": "5aae1b5f",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Text(0.5, 1.0, 'Opened')"
]
},
"execution_count": 202,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAlYAAAHFCAYAAAAwv7dvAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuNCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8QVMy6AAAACXBIWXMAAAsTAAALEwEAmpwYAAEAAElEQVR4nOy9d6AlRZn+/6nuPvHmmXsn50DOQbKYM6KwYgB0V1dRzLtr1t8qu+IacXHNCuiaFhf97ooRzCCwMkoY4uRw5+Z8cof6/VFd1dXn3hkGGHSA8+hwz+lQXV1Vp9+nn/ett4SUkhZaaKGFFlpooYUWHj2cv3YFWmihhRZaaKGFFp4oaBGrFlpooYUWWmihhQOEFrFqoYUWWmihhRZaOEBoEasWWmihhRZaaKGFA4QWsWqhhRZaaKGFFlo4QGgRqxZaaKGFFlpooYUDhBaxauEJBSHENUKIf/1r16OFFlp4fEII8SUhxIf+2vVo4fGLFrFqYRaEEK8QQtwmhCgLIYbjz5cKI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o3iFWWPjMe7yJR1xISd/DhkT2/Wmjh8YFiscgxxxzDhRdeyKpVq/Z57NatW/n85z/Pgw8++Jep3BMEj5VihZTyJ8BP9vd4TZLUuQIndosZZQqtQsVHi+Tt1zyihdR21KhA8eGxGhWTE02C7PqqC8fXEfoeVB3M9WOXkjlHG3bLEKVcmIkZNzzEEAIJOEQiIYAiNqFaCdK6gozA0WTT3I+l2ljlJ2QoVsJE2lWkq6eJnyEsMiFfhggZLiXiy2klQ19RWE2b3L8UICNpeSctxcVWWywlJCENttJkkYmUG1gbdctI201j1wW
"text/plain": [
"<Figure size 720x576 with 3 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"coins = cv.imread(\"img/coins.png\")\n",
"coins_gray = cv.cvtColor(coins, cv.COLOR_BGR2GRAY)\n",
"_, coins_bin = cv.threshold(coins_gray, 160, 255, cv.THRESH_BINARY_INV)\n",
"\n",
"\n",
"kernel = cv.getStructuringElement(cv.MORPH_ELLIPSE, (7, 7))\n",
"\n",
"coins_opened = cv.morphologyEx(coins_bin, cv.MORPH_CLOSE, kernel, iterations=1)\n",
"\n",
"\n",
"plt.figure(figsize=[10,8])\n",
"plt.subplot(221)\n",
"plt.imshow(coins, cmap='gray')\n",
"plt.title(\"Grayscale\")\n",
"plt.subplot(222)\n",
"plt.imshow(coins_bin, cmap='gray')\n",
"plt.title(\"Binary\")\n",
"plt.subplot(223)\n",
"plt.imshow(coins_opened, cmap='gray')\n",
"plt.title(\"Opened\")"
]
},
{
"cell_type": "code",
"execution_count": 203,
"id": "c296a5ef",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"No. of contours: 6\n"
]
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAcAAAAEyCAYAAABtfwBhAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuNCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8QVMy6AAAACX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9mcOqye/CERetQoAmBZChQogxjQZIARPcr8iZ0KCEp5YL3s/bR+2tpEdCMZ/mRgF6kGMo4OAbwpcDMekd0mGVXZd4AIND2bZtavyF9V6B0LgzGrUA+PTjWS6qtQhHLArQG6eZhj0EQqNyf0gsWbkf3qawtqVZfDOuILUYG3RIufplcm5jDwoMggOYlMGKjMrCxxWlZitLuuIBuXWfdhm7HGswt0OT9xrF2gpX3CLRJbd1p0JNtiqDYNa7QrkGBY6MW01BvB6O91LvEFod1n0K7aA9eYhnzvWcLT2J6WrkVpbFAZSl95PynY/k1OQ7+hwvq5fNXyu3bUW7fjqkfAa770bPwxReejtf/8Nexole5TQuIK10U98o6LJDVlqEfec+B9j2S+1MaSmzK1WndZw7xsNIWtkPMHh4H+LR1Z5GGLPDSyzlOr4kwljdpXAtUs91Z5hUAAu2bxy68SGM3YgjsBuVtu5hUqWWaHMKDMS8vfR6RcbRFCFQAyW4u3c44kiK26P4yEEof+Zrx4JJydTLA8vFLuODu5GPysay+DQjQuwbilHabknEAXV+30G/6rV8PHVvg5UDsAuy7ogGcGqA0e5QBS7tWuW8abPV6AEER0VZ1SuRcYld5wwCVmF5qMNaAx8JsxaiP9W/NfC69q4GgeW4++Y2n4eQ/vQHF5oeS5zB
"text/plain": [
"<Figure size 720x360 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"shapes_contours, _ = cv.findContours(coins_opened, cv.RETR_EXTERNAL, cv.CHAIN_APPROX_SIMPLE)\n",
"print(f\"No. of contours: {len(shapes_contours)}\")\n",
"# shapes_with_contours = coins.copy()\n",
"\n",
"\n",
"shapes_with_bb = coins_gray.copy()\n",
"\n",
"# cv.drawContours(shapes_with_contours, shapes_contours, -1, (255,255,0), 2)\n",
"for idx, contour in enumerate(shapes_contours):\n",
" (x,y), radius = cv.minEnclosingCircle(contour)\n",
" cv.circle(shapes_with_bb, (int(x),int(y)), int(round(radius)), (0,0,0), -1)\n",
"# cv.putText(shapes_with_bb, str(idx + 1), (int(x-10),int(y+10)), cv.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 2)\n",
" \n",
"plt.figure(figsize=[10,5])\n",
"plt.imshow(shapes_with_bb);"
]
},
{
"cell_type": "code",
"execution_count": 204,
"id": "365ce640",
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAfcAAAEzCAYAAAAsDEqFAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuNCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8QVMy6AAAACXBIWXMAAAsTAAALEwEAmpwYAABOn0lEQVR4nO3dd5xU1f3/8ddnZnZ2tgHL0pt0FBCxYUNFbKhBosYaE1tEBU355vtNNE3zy9fEJN8YNREVo9Ekdo0FRewEsSCgWKgCUpZel93ZOjOf3x874CrbZndmzpTPM4/7WGbmzty3N7CfOeeee46oKsYYY4zJHB7XAYwxxhgTX1bcjTHGmAxjxd0YY4zJMFbcjTHGmAxjxd0YY4zJMFbcjTHGmAxjxd0YY4xJAyLSSUSeFpFlIrJURI5pat+EFXcRmSAiy0VkpYjcmKjjGGOMMVniTmCWqh4IHAIsbWpHScQkNiLiBVYApwKlwHzgYlVdEveDGWOMMRlORDoAHwMDtRWFO1Et9zHASlVdraq1wOPApAQdyxhjjMl0A4FtwN9F5CMR+ZuIFDS1sy9BIXoD6xs8LgWOariDiEwGJkcfHp6gHMaYrCbRnzbNdpbbrqpdk3Ww0yeM0h3bK2J6z8KFXywGqhs8NV1Vpzd47AMOA25Q1XkicidwI/DLxj4vUcVdGnnuK/+6oqGnA4iIgjdBUYwxmawgdxA+T26jr+V6CsmXYnaF1zf6OkBZ1XIgnKB0JjWE1ybzaDu2VzBvwW9ieo9PLq1W1SOa2aUUKFXVedHHT1Nf3Bv/vJiO3nqlQN8Gj/sAGxN0LGNMFumYN5xO3l77HhdHuuLRxtoTQKT+R2dKmvy8nYV90WhxDxOitGJ2vKKaL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output_type": "display_data"
}
],
"source": [
"_, coins_binary = cv.threshold(shapes_with_bb, 127, 255, cv.THRESH_BINARY_INV)\n",
"\n",
"_, coins_labels = cv.connectedComponents(coins_binary)\n",
"\n",
"\n",
"for idx, contour in enumerate(shapes_contours):\n",
" (x,y), radius = cv.minEnclosingCircle(contour)\n",
" cv.putText(coins_labels, str(idx + 1), (int(x-10),int(y+10)), cv.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 0), 2)\n",
"\n",
"\n",
"\n",
"plt.figure(figsize=[10,5])\n",
"\n",
"\n",
"plt.imshow(coins_labels, cmap='inferno')\n",
"plt.colorbar();"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c6910eba",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "2633aff0",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.8"
}
},
"nbformat": 4,
"nbformat_minor": 5
}