问题
I have a image with ID card, Bank card and signature i want to get id_card.jpg
and bank_card.jpg
and signature.jpg
.
The problem ID card and Bank card has the same width and height, i don't know how to detect each other. But the color is different suggestion possible get by color or the best idea is to get name of each card and after crop each card by name ??
I'm so new in this domain and i work in emergency project that why i will very grateful if someone can help me.
The image look like
With this code i get only bank card, not work like i want :(
# I want here to get name of each object i dont know how after loop and crop
for i in range(len(contours)):
area = cv2.contourArea(contours[i])
if hierarchy[i][3] == -1:
cv2.drawContours(orig, contours, -1, (0, 255, 0), 3)
I can get draw now i need to crop.
So how can i get name of each object and crop using opencv and deep learning and thanks?
回答1:
there's a plenty of things you could do, a good way is to crop the logo at the most top corner of the Mastercard or the id card, and save it as template, than every time you want to check if it's Mastercard you look for a good match between the logo and the image, if you find a good match than this is a MasterCard. Here is a simple code to do a template matching using opencv
image = cv2.imread("scan.jpg")
template = cv2.imread("masterCardLogo.jpg")
res = cv2.matchTemplate(image,template,cv2.TM_SQDIFF_NORMED)
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)
if(max_val>0.5):
print("This is a master Card")
as I mentioned before, there are a lot of other methods, like the following
- Do Feature Matching with another template image https://docs.opencv.org/master/dc/dc3/tutorial_py_matcher.html
- You can find the edges in each picture and the one with more edges will be the ID card https://docs.opencv.org/master/da/d22/tutorial_py_canny.html
- You can use OCR by using Tessract library, to look for the word MasterCard or any special Word in the ID card https://www.pyimagesearch.com/2017/07/10/using-tesseract-ocr-python/
来源:https://stackoverflow.com/questions/65127788/detect-object-by-name-of-card-and-crop-it-using-opencv