

{"id":115662,"date":"2024-02-12T18:00:12","date_gmt":"2024-02-12T12:30:12","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=115662"},"modified":"2026-06-01T12:28:12","modified_gmt":"2026-06-01T06:58:12","slug":"image-reverse-search-engine-project","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/image-reverse-search-engine-project\/","title":{"rendered":"OpenCV Project &#8211; Image Reverse Search Engine"},"content":{"rendered":"<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:163,&quot;href&quot;:&quot;https:\\\/\\\/www.kaggle.com\\\/datasets\\\/andrewmvd\\\/animal-faces&quot;,&quot;archived_href&quot;:&quot;http:\\\/\\\/web-wp.archive.org\\\/web\\\/20250814090058\\\/https:\\\/\\\/www.kaggle.com\\\/datasets\\\/andrewmvd\\\/animal-faces&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2025-12-06 13:37:16&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-12 21:04:50&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-02 12:34:01&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-06 04:03:43&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-11 10:03:19&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-20 01:26:02&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-30 10:10:39&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-03 15:19:36&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-12 09:27:38&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-16 04:07:05&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-19 14:53:18&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-26 17:31:39&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-05 17:38:19&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-13 20:27:54&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-19 14:47:39&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-28 17:52:17&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-01 06:53:23&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-04 12:45:17&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-08 01:25:57&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-11 09:49:04&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-18 19:18:23&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-22 22:17:13&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-30 19:06:29&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-08 17:16:17&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-14 05:14:55&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-18 23:39:29&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-21 23:48:48&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-02 00:59:38&quot;,&quot;http_code&quot;:200}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-06-02 00:59:38&quot;,&quot;http_code&quot;:200},&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:2539,&quot;href&quot;:&quot;https:\\\/\\\/drive.google.com\\\/file\\\/d\\\/13NYnTtqIeWsAijs8qvsEEg36C2ufofMl\\\/view?usp=drive_link&quot;,&quot;archived_href&quot;:&quot;http:\\\/\\\/web-wp.archive.org\\\/web\\\/20260601065829\\\/https:\\\/\\\/drive.google.com\\\/file\\\/d\\\/13NYnTtqIeWsAijs8qvsEEg36C2ufofMl\\\/view?usp=drive_link&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-06-02 09:34:53&quot;,&quot;http_code&quot;:200}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-06-02 09:34:53&quot;,&quot;http_code&quot;:200},&quot;process&quot;:&quot;done&quot;}]'><\/div>\n<p>An image reverse search engine is a plagiarism detection tool that enables searching the internet using an image instead of text. By uploading or providing an image&#8217;s URL, you can find similar images, discover the original source, and gather more information.<\/p>\n<p>These engines use advanced algorithms to analyze visual features and compare the uploaded image with a vast database of indexed images. They are useful for identifying landmarks, verifying image authenticity, finding design inspiration, and combating misinformation. Image reverse search engines help us explore, discover, and make sense of the visual world online.<\/p>\n<h2>Dataset<\/h2>\n<p>The animal face <a href=\"https:\/\/www.kaggle.com\/datasets\/andrewmvd\/animal-faces\">dataset<\/a> is a curated collection of images specifically focused on the faces of cats, dogs, and various wild animals. It serves as a valuable resource for training and developing computer vision algorithms that can recognize and classify animal faces accurately. The dataset includes a diverse range of images capturing different breeds and species, showcasing the distinct facial features, expressions, and characteristics of each animal.<\/p>\n<h3>Techniques<\/h3>\n<p>Image reverse search engines use advanced techniques, such as computer vision algorithms and deep learning, to efficiently find similar images. They analyze visual features, compare them to a database, and employ efficient indexing for faster searches. Meta-data analysis adds contextual information. These engines assist in tasks like source verification and content discovery.<\/p>\n<h3>What is NearestNeighbors?<\/h3>\n<p>NearestNeighbors is an algorithm that helps find the closest neighbors to a given data point. It is used in various applications like recommendation systems, image processing, and anomaly detection. It efficiently calculates distances and retrieves the nearest neighbors based on a chosen metric. NearestNeighbors is a versatile and powerful tool for finding similar or relevant items in a dataset.<\/p>\n<h3>Ball Tree Algorithm<\/h3>\n<p>The ball tree algorithm used in the NearestNeighbors class is an efficient way to find nearest neighbors. It organizes data into nested hyperspheres (balls) in a tree structure. This allows for quick searches by recursively traversing the tree. The algorithm is particularly good at handling high-dimensional data and is robust to noise. It is widely used in applications like image recognition and recommendation systems.<\/p>\n<h3>Prerequisites for Image Reverse Search Engine using OpenCV<\/h3>\n<p>A strong grasp of both the Python programming language and the OpenCV library is essential. Apart from this, you should have the following system requirements.<\/p>\n<p>1. Python 3.7 and above<br \/>\n2. Google Colab<\/p>\n<h3>Download OpenCV Image Reverse Search Engine Project<\/h3>\n<p>Please download the source code of OpenCV Image Reverse Search Engine Project: <a href=\"https:\/\/drive.google.com\/file\/d\/13NYnTtqIeWsAijs8qvsEEg36C2ufofMl\/view?usp=drive_link\"><strong>OpenCV Image Reverse Search Engine Project Code.<\/strong><\/a><\/p>\n<h3>Why Google Colab?<\/h3>\n<p>Google Colab is a user-friendly online Python coding platform. It provides access to high-performance cloud-based computers equipped with ample memory and fast processors. This enables seamless handling of large datasets and efficient training of machine learning models. With no need for local installations, Colab simplifies collaboration by allowing easy sharing of work. It comes pre-loaded with popular libraries used in machine learning, enabling users to get started quickly. For optimal performance, it is advisable to use Google Colab if your computer has a dedicated graphics card with 4-8 GB memory.<\/p>\n<h3>Let\u2019s Implement It<\/h3>\n<p>First of all, change the Google colab runtime to GPU from the Runtime option available in the menu section.<\/p>\n<p>1. These lines of code set the environment variables &#8216;KAGGLE_USERNAME&#8217; and &#8216;KAGGLE_KEY&#8217; to your Kaggle account&#8217;s username and API key, respectively.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import os \r\nos.environ['KAGGLE_USERNAME'] = \"yogeshkhandare56\"\r\nos.environ['KAGGLE_KEY'] = \"7788f9b761a1a8f81219c7927e26a42c\"<\/pre>\n<p>2. This is the API command of the dataset required to download the dataset. It is in zip format.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">!kaggle datasets download -d andrewmvd\/animal-faces<\/pre>\n<p>3. This line of code unzips the data.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">!unzip animal-faces.zip<\/pre>\n<p>4. Importing all the necessary libraries that are required during implementation.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">from numpy.linalg import norm\r\nfrom tqdm import tqdm\r\nfrom sklearn.neighbors import NearestNeighbors\r\nimport matplotlib.pyplot as plt\r\nimport matplotlib.image as mpimg\r\nfrom sklearn.decomposition import PCA\r\nimport os\r\nimport PIL\r\nimport os\r\nimport numpy as np\r\nimport time\r\nimport tensorflow as tf\r\nfrom tensorflow.keras.preprocessing import image\r\nfrom tensorflow.keras.preprocessing.image import ImageDataGenerator\r\nfrom tensorflow.keras.applications.resnet50 import ResNet50, preprocess_input\r\nimport math<\/pre>\n<p>5. It sets the image size variable to 440 pixels. It then creates a ResNet50 model using pre-trained weights from the ImageNet dataset. The model is configured to exclude the final classification layer. It expects input images of size 440&#215;440 pixels with 3 color channels. The model uses maximum pooling for feature extraction.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">img_size =440\r\n\r\nmodel = ResNet50(weights='imagenet', include_top=False,input_shape=(img_size, img_size, 3),pooling='max')<\/pre>\n<p>6. It sets the batch size variable to 64.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">batch_size = 64<\/pre>\n<p>7. It specifies the dataset path variable as &#8216;\/content\/afhq\/train&#8217;.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">DataSet = '\/content\/afhq\/train'<\/pre>\n<p>8. The code sets up an image data generator and a data generator for a dataset. The generators preprocess the images and provide them in batches without class labels and without shuffling.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Image_gen = ImageDataGenerator(preprocessing_function=preprocess_input)\r\n\r\nDatagen = Image_gen.flow_from_directory(DataSet,\r\n                                        target_size=(img_size, img_size),\r\n                                        batch_size=batch_size,\r\n                                        class_mode=None,\r\n                                        shuffle=False)<\/pre>\n<p>9. The code determines the total number of images in the dataset and stores it in &#8216;total_img&#8217;. It then calculates the number of epochs needed to train on the dataset and saves it in &#8216;total_epochs&#8217;.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">total_img = len(Datagen.filenames)\r\ntotal_epochs = int(math.ceil(total_img \/ batch_size))<\/pre>\n<p>10. The code generates predictions using the trained model on the dataset and stores them in feature_list.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">feature_list = model.predict_generator(Datagen, total_epochs,verbose = 1)<\/pre>\n<p><b>Output of this step<\/b><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/generates-predictions.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-132002 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/generates-predictions.webp\" alt=\"generates predictions\" width=\"1321\" height=\"427\" \/><\/a><\/p>\n<p>11. The code prints the total number of images in the dataset and the shape of the feature list.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">print(\"Total Images is \", len(Datagen.classes))\r\nprint(\"Shape of feature_list is \", feature_list.shape)<\/pre>\n<p><strong> Output of this step<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/feature-list.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-132003 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/feature-list.webp\" alt=\"feature list\" width=\"1009\" height=\"175\" \/><\/a><\/p>\n<p>12. The code creates a list of file paths by combining the dataset directory and each filename in the dataset.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">filenames = [DataSet + '\/' + s for s in Datagen.filenames]<\/pre>\n<p>13. This code finds the closest neighbors based on features in a given list. It uses the &#8220;ball tree&#8221; algorithm for efficiency.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">neighbors = NearestNeighbors(n_neighbors=5,\r\n                             algorithm='ball_tree',\r\n                             metric='euclidean')\r\nneighbors.fit(feature_list)<\/pre>\n<p><strong> Output of this step<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/ball-tree.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-132004 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/ball-tree.webp\" alt=\"ball tree\" width=\"894\" height=\"118\" \/><\/a><\/p>\n<p>14. It defines a function called similar_images that takes in a variable called indices. It then proceeds to plot a grid of images based on the values in the indices variable. The images are loaded from specific filenames using mpimg.imread(), and the plot is organized in a 2&#215;4 grid using subplots. Finally, the shape of the indices variable is printed.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">def similar_images(indices):\r\n    plt.figure(figsize=(15,10), facecolor='white')\r\n    plotnumber = 1    \r\n    for index in indices:\r\n        if plotnumber&lt;=len(indices) :\r\n            ax = plt.subplot(2,4,plotnumber)\r\n            plt.imshow(mpimg.imread(filenames[index]), interpolation='lanczos')            \r\n            plotnumber+=1\r\n    plt.tight_layout()\r\n\r\nprint(indices.shape)<\/pre>\n<p>15. First it gives the title \u201cImage Reverse Search Engine\u201d to the window. It gives the option to upload an image from the system, resize it, convert it to a numerical array, expand its dimensions, and apply preprocessing steps for further processing.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">print(\"\\033[1m\\033[91m----------------------------------------Image Reverse Search Engine---------------------------------\\033[0m\")\r\nuploaded_files = files.upload()\r\nuploaded_image = uploaded_files[next(iter(uploaded_files))]\r\nimg = Image.open(io.BytesIO(uploaded_image))\r\ninput_shape = (img_size, img_size, 3)\r\nimg = img.resize((input_shape[0], input_shape[1]))\r\nimg_array = np.array(img)\r\nexpanded_img_array = np.expand_dims(img_array, axis=0)\r\npreprocessed_img = preprocess_input(expanded_img_array)<\/pre>\n<p>16. The code predicts features for a test image using a machine learning model and then finds the nearest neighbors based on those features using a NearestNeighbors object.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">test_img_features = model.predict(preprocessed_img, batch_size=1)\r\n\r\n_, indices = neighbors.kneighbors(test_img_features)<\/pre>\n<p>17. It prints the shape of the indices variable, which indicates the number of nearest neighbors found. It then displays the input image using a specific interpolation method. After that, it prints a section divider and a header indicating &#8220;Similar Images.&#8221; Finally, it shows a set of similar images based on the indices obtained from the nearest neighbors.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">plt.imshow(img, interpolation='lanczos')\r\nplt.title('----------------------------------------Input Image---------------------------------')\r\nplt.axis('off')\r\nplt.show()\r\nprint(\"\\033[1m\\033[91m----------------------------------------Similar Images---------------------------------\\033[0m\")\r\nsimilar_images(indices[0])<\/pre>\n<h3>OpenCV Image Reverse Search Engine Output<\/h3>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/image-reverse-search-engine-output.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-132005 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/image-reverse-search-engine-output.webp\" alt=\"image reverse search engine output\" width=\"1920\" height=\"1080\" \/><\/a><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/output-image-reverse-search-engine.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-132006 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/output-image-reverse-search-engine.webp\" alt=\"image reverse search engine output\" width=\"1920\" height=\"1080\" \/><\/a><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/image-reverse-search-engine-upload-file.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-132007 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/image-reverse-search-engine-upload-file.webp\" alt=\"image reverse search engine upload file\" width=\"1474\" height=\"677\" \/><\/a><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/image-reverse-search-engine.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-132008 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/image-reverse-search-engine.webp\" alt=\"image reverse search engine \" width=\"1920\" height=\"1080\" \/><\/a><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/opencv-image-reverse-search-engine-.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-132009 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/opencv-image-reverse-search-engine-.webp\" alt=\"opencv image reverse search engine\" width=\"1920\" height=\"1080\" \/><\/a><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/opencv-image-reverse-search-engine-output-1.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-132012 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/opencv-image-reverse-search-engine-output-1.webp\" alt=\"opencv image reverse search engine output\" width=\"1648\" height=\"884\" \/><\/a><\/p>\n<p><strong>Full Code<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import os\r\nos.environ['KAGGLE_USERNAME'] = \"yogeshkhandare56\"\r\nos.environ['KAGGLE_KEY'] = \"7788f9b761a1a8f81219c7927e26a42c\"\r\n!kaggle datasets download -d andrewmvd\/animal-faces\r\n\r\n!unzip animal-faces.zip\r\n\r\nfrom numpy.linalg import norm\r\nfrom tqdm import tqdm\r\nfrom sklearn.neighbors import NearestNeighbors\r\nimport matplotlib.pyplot as plt\r\nimport matplotlib.image as mpimg\r\nfrom sklearn.decomposition import PCA\r\nimport os\r\nimport PIL\r\nimport os\r\nimport numpy as np\r\nimport time\r\nimport tensorflow as tf\r\nfrom tensorflow.keras.preprocessing import image\r\nfrom tensorflow.keras.preprocessing.image import ImageDataGenerator\r\nfrom tensorflow.keras.applications.resnet50 import ResNet50, preprocess_input\r\n\r\nimport math\r\n\r\nimg_size =440\r\n\r\nmodel = ResNet50(weights='imagenet', include_top=False,input_shape=(img_size, img_size, 3),pooling='max')\r\n\r\nbatch_size = 64\r\nDataSet = '\/content\/afhq\/train'\r\n\r\nImage_gen = ImageDataGenerator(preprocessing_function=preprocess_input)\r\n\r\nDatagen = Image_gen.flow_from_directory(DataSet,\r\n                                        target_size=(img_size, img_size),\r\n                                        batch_size=batch_size,\r\n                                        class_mode=None,\r\n                                        shuffle=False)\r\n\r\ntotal_img = len(Datagen.filenames)\r\ntotal_epochs = int(math.ceil(total_img \/ batch_size))\r\n\r\nfeature_list = model.predict_generator(Datagen, total_epochs,verbose = 1)\r\n\r\nfeature_list\r\n\r\nprint(\"Total Images is \", len(Datagen.classes))\r\nprint(\"Shape of feature_list is \", feature_list.shape)\r\n\r\nfilenames = [DataSet + '\/' + s for s in Datagen.filenames]\r\n\r\nneighbors = NearestNeighbors(n_neighbors=5,\r\n                             algorithm='ball_tree',\r\n                             metric='euclidean')\r\nneighbors.fit(feature_list)\r\n\r\nfrom google.colab import files\r\nimport numpy as np\r\nfrom PIL import Image\r\nimport io\r\nimport matplotlib.pyplot as plt\r\nimport matplotlib.image as mpimg\r\n\r\nprint(\"\\033[1m\\033[91m----------------------------------------Image Reverse Search Engine---------------------------------\\033[0m\")\r\nprint(\"\\n\")\r\nprint(\"\\n\")\r\n\r\nuploaded_files = files.upload()\r\n\r\nuploaded_image = uploaded_files[next(iter(uploaded_files))]\r\n\r\nimg = Image.open(io.BytesIO(uploaded_image))\r\n\r\ninput_shape = (img_size, img_size, 3)\r\nimg = img.resize((input_shape[0], input_shape[1]))\r\nimg_array = np.array(img)\r\nexpanded_img_array = np.expand_dims(img_array, axis=0)\r\npreprocessed_img = preprocess_input(expanded_img_array)\r\n\r\ntest_img_features = model.predict(preprocessed_img, batch_size=1)\r\n\r\n_, indices = neighbors.kneighbors(test_img_features)\r\n\r\ndef similar_images(indices):\r\n    num_images = len(indices)\r\n    num_columns = 4\r\n    num_rows = (num_images - 1) \/\/ num_columns + 1\r\n    plt.figure(figsize=(15, num_rows*5), facecolor='white')\r\n\r\n    for i, index in enumerate(indices):\r\n        ax = plt.subplot(num_rows, num_columns, i+1)\r\n        ax.axis('off')\r\n        plt.imshow(mpimg.imread(filenames[index]), interpolation='lanczos')\r\n\r\n    plt.tight_layout()\r\n\r\nprint(indices.shape)\r\n\r\nplt.imshow(img, interpolation='lanczos')\r\nplt.title('----------------------------------------Input Image---------------------------------')\r\nplt.axis('off')\r\nplt.show()\r\n\r\nprint(\"\\033[1m\\033[91m----------------------------------------Similar Images---------------------------------\\033[0m\")\r\nsimilar_images(indices[0])<\/pre>\n<h3>Conclusion<\/h3>\n<p>An image reverse search engine using the nearest neighbor and ball tree algorithm is a powerful tool for finding similar images. It works by organizing image features in a way that allows for quick and accurate searches.<\/p>\n<p>This technology has many practical applications, including helping users find visually similar images, recommending related content, and analyzing visual similarities. By using this image reverse search engine, users can enjoy improved search experiences and easily explore diverse image collections.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>An image reverse search engine is a plagiarism detection tool that enables searching the internet using an image instead of text. By uploading or providing an image&#8217;s URL, you can find similar images, discover&#46;&#46;&#46;<\/p>\n","protected":false},"author":86671,"featured_media":132015,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27755],"tags":[30141,30140,30142,21719,30129,30118,30143],"class_list":["post-115662","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-opencv-tutorials","tag-image-reverse-search-engine-using-opencv","tag-opencv-image-reverse-search-engine","tag-opencv-image-reverse-search-engine-project","tag-opencv-projects","tag-opencv-projects-for-practice","tag-python-opencv-projects","tag-python-opencv-projects-ideas"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>OpenCV Project - Image Reverse Search Engine - DataFlair<\/title>\n<meta name=\"description\" content=\"An OpenCV image reverse search engine using the nearest neighbor and ball tree algorithm is a powerful tool for finding similar images.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/image-reverse-search-engine-project\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"OpenCV Project - Image Reverse Search Engine - DataFlair\" \/>\n<meta property=\"og:description\" content=\"An OpenCV image reverse search engine using the nearest neighbor and ball tree algorithm is a powerful tool for finding similar images.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/image-reverse-search-engine-project\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2024-02-12T12:30:12+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-06-01T06:58:12+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/opencv-image-reverse-search-engine.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"OpenCV Project - Image Reverse Search Engine - DataFlair","description":"An OpenCV image reverse search engine using the nearest neighbor and ball tree algorithm is a powerful tool for finding similar images.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/image-reverse-search-engine-project\/","og_locale":"en_US","og_type":"article","og_title":"OpenCV Project - Image Reverse Search Engine - DataFlair","og_description":"An OpenCV image reverse search engine using the nearest neighbor and ball tree algorithm is a powerful tool for finding similar images.","og_url":"https:\/\/data-flair.training\/blogs\/image-reverse-search-engine-project\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2024-02-12T12:30:12+00:00","article_modified_time":"2026-06-01T06:58:12+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/opencv-image-reverse-search-engine.webp","type":"image\/webp"}],"author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/image-reverse-search-engine-project\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/image-reverse-search-engine-project\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/0e594f928e31fc96628ac40f6ae74f49"},"headline":"OpenCV Project &#8211; Image Reverse Search Engine","datePublished":"2024-02-12T12:30:12+00:00","dateModified":"2026-06-01T06:58:12+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/image-reverse-search-engine-project\/"},"wordCount":1081,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/image-reverse-search-engine-project\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/opencv-image-reverse-search-engine.webp","keywords":["image reverse search engine using opencv","opencv image reverse search engine","opencv image reverse search engine project","opencv projects","opencv projects for practice","python opencv projects","python opencv projects ideas"],"articleSection":["OpenCV Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/image-reverse-search-engine-project\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/image-reverse-search-engine-project\/","url":"https:\/\/data-flair.training\/blogs\/image-reverse-search-engine-project\/","name":"OpenCV Project - Image Reverse Search Engine - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/image-reverse-search-engine-project\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/image-reverse-search-engine-project\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/opencv-image-reverse-search-engine.webp","datePublished":"2024-02-12T12:30:12+00:00","dateModified":"2026-06-01T06:58:12+00:00","description":"An OpenCV image reverse search engine using the nearest neighbor and ball tree algorithm is a powerful tool for finding similar images.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/image-reverse-search-engine-project\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/image-reverse-search-engine-project\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/image-reverse-search-engine-project\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/opencv-image-reverse-search-engine.webp","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/opencv-image-reverse-search-engine.webp","width":1200,"height":628,"caption":"opencv image reverse search engine"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/image-reverse-search-engine-project\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"OpenCV Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/opencv-tutorials\/"},{"@type":"ListItem","position":3,"name":"OpenCV Project &#8211; Image Reverse Search Engine"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/0e594f928e31fc96628ac40f6ae74f49","name":"TechVidvan Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/c89190da3d4010c71ba476b618ab10fdc2335c82cdfa0ad5002d98d0f2473444?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/c89190da3d4010c71ba476b618ab10fdc2335c82cdfa0ad5002d98d0f2473444?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c89190da3d4010c71ba476b618ab10fdc2335c82cdfa0ad5002d98d0f2473444?s=96&d=mm&r=g","caption":"TechVidvan Team"},"description":"TechVidvan Team provides high-quality content &amp; courses on AI, ML, Data Science, Data Engineering, Data Analytics, programming, Python, DSA, Android, Flutter, full stack web dev, MERN, and many latest technology.","url":"https:\/\/data-flair.training\/blogs\/author\/test001\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/115662","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/86671"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=115662"}],"version-history":[{"count":9,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/115662\/revisions"}],"predecessor-version":[{"id":148613,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/115662\/revisions\/148613"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/132015"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=115662"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=115662"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=115662"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}