diff --git a/Coding/Python/Template matching.ipynb b/Coding/Python/Template matching.ipynb new file mode 100644 index 0000000..e8358f8 --- /dev/null +++ b/Coding/Python/Template matching.ipynb @@ -0,0 +1,61 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import cv2\n", + "import numpy as np\n", + "\n", + "img_rgb = cv2.imread('temp.jpg')\n", + "img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)\n", + "\n", + "template = cv2.imread('1.jpg',0)\n", + "w, h = template.shape[::-1]\n", + "res = cv2.matchTemplate(img_gray,template,cv2.TM_CCOEFF_NORMED)\n", + "threshold = 1.0\n", + "loc = np.where( res >= threshold)\n", + "for pt in zip(*loc[::-1]):\n", + " cv2.rectangle(img_rgb, pt, (pt[0] + w, pt[1] + h), (0,255,255), 2)\n", + "\n", + "cv2.imshow('Detected',img_rgb)\n", + "cv2.waitKey()\n", + "cv2.destroyAllWindows" + ] + } + ], + "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.0" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +}