Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

opencv find image contained within an image

import cv2

method = cv2.TM_SQDIFF_NORMED

# Read the images from the file
small_image = cv2.imread('small_image.png')
large_image = cv2.imread('large_image.jpeg')

result = cv2.matchTemplate(small_image, large_image, method)

# We want the minimum squared difference
mn,_,mnLoc,_ = cv2.minMaxLoc(result)

# Draw the rectangle:
# Extract the coordinates of our best match
MPx,MPy = mnLoc

# Step 2: Get the size of the template. This is the same size as the match.
trows,tcols = small_image.shape[:2]

# Step 3: Draw the rectangle on large_image
cv2.rectangle(large_image, (MPx,MPy),(MPx+tcols,MPy+trows),(0,0,255),2)

# Display the original image with the rectangle around the match.
cv2.imshow('output',large_image)

# The image is only displayed if we call this
cv2.waitKey(0)
Comment

PREVIOUS NEXT
Code Example
Python :: join mulitple dataframe pandas index 
Python :: Python OPERATORS, Data Types: LIST, SET, TUPLE, DICTIONARY 
Python :: python assertEqual tuple list 
Python :: Python OrderedDict - LRU 
Python :: pd sample every class 
Python :: import numpy as np import matplotlib.pyplot as plt index = 0 missClassifiedIndexes = [] for label, predit in zip(y_test, predictions): if label != predict: missClassifiedIndexes.append(index) index = +1 
Python :: Delete all small Latin letters a from the given string. 
Python :: python function pointer with multiple args 
Python :: if statement collection python 
Python :: reverse words and swapcase in python 
Python :: kill os system by pid python script 
Python :: HttpResponse Object Error in view.py 
Python :: python django creating products 
Python :: osrm python 
Python :: daemon in os 
Python :: while loop choosing numbers 
Python :: Make Latest pyhton as default in mac 
Python :: is 2 an even number 
Python :: pyqt curves exemple 
Python :: pytest handling muliple cases 
Python :: pytest rerun last failed 
Python :: how to make python faster 
Python :: geopandas change dtype of a columns 
Python :: free function in python 
Python :: how to put words into list 
Python :: arma-garch python 
Python :: paschat opposite sanskrit 
Python :: checking number of connected users hotspot ubuntu 
Python :: dip programming language 
Python :: Can I convert python code to C++? 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =