python_developer
1.54K subscribers
3.74K photos
1.97K videos
232 files
434 links
کانال اموزش پایتون @Real_developer
تبلیغات پذیرفته میشود.
Download Telegram
تصویر بزرگتر
تصویر الگو
import cv2
import numpy as np
from matplotlib import pyplot as plt

img_rgb = cv2.imread('111.png')
img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
template = cv2.imread('1111.PNG',0)
w, h = template.shape[::-1]

res = cv2.matchTemplate(img_gray,template,cv2.TM_CCOEFF_NORMED)
threshold = 0.8
loc = np.where( res >= threshold)
for pt in zip(*loc[::-1]):
cv2.rectangle(img_rgb, pt, (pt[0] + w, pt[1] + h), (0,0,255), 2)

cv2.imwrite('res.png',img_rgb)
💢💢💢💢
تصویر res.png را که داخل پوشه ایجاد شده را باز میکنیم:
💢💢💢
اصلش باید اینطوری باشه 🤔
This media is not supported in your browser
VIEW IN TELEGRAM
💢اولین پروژه💢
1) تشخیص و شمردن سکه ها
💢
تصویر اصلی
python_developer
تصویر اصلی
💢💢💢💢💢💢💢💢💢
ادامه:👇🏻👇🏻👇🏻👇🏻👇🏻
1️⃣پیش پردازش:
مرحله اول :
تصویر را به حالت grayscale برده تا توسط Gaussian blur، تصویر مات و نویز ها حذف شود.
مرحله دوم:
سپس آستانه گذاری ساده بر روی تصویر پیش پردازش شده اعمال میکنیم.


💢💢💢💢💢
‍ import cv2

def sufra():
img = cv2.imread('coins.jpg')
coins_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
cv2.namedWindow('image', cv2.WINDOW_NORMAL)
coins_preprocessed = cv2.GaussianBlur(coins_gray, (5, 5), 0)
_, coins_binary = cv2.threshold(coins_preprocessed, 130, 255, cv2.THRESH_BINARY)
coins_binary = cv2.bitwise_not(coins_binary)

cv2.imshow('image', coins_binary)
cv2.waitKey(0)
cv2.destroyAllWindows()
print ("waitkey")

if name == 'main':
sufra()
💢💢💢💢💢
2️⃣پیدا کردن کانتور ها(contours)
کانتورها ، نقاط دنباله دار، که یک منحنی بسته راتشکیل داده و در بر دارنده تصویر هستند.
💢کانتور ها ابزاری مفیدبرای تشخیص اشیا و ویژگیها، همچنینن تجزیه و تحلیل اشکال، هستند.
با استفاده از cv2.findContours ()، مرز یا لبه های هر سکه را پیدا خواهیم کرد.
انتخاب پرچم
cv2.RETR_EXTERNAL،
تنها خطوط خارجی را به تابع باز می گرداند. بنابراین جزئيات کوچکتر روی سطح سکه را انتخاب نمی کند.
برای به دست آوردن محدوده کانتورها، ما از cv2.contourArea () استفاده می کنیم.


💢💢
https://docs.opencv.org/3.3.1/d4/d73/tutorial_py_contours_begin.html
🔎جهت مطالعه بیشتر
💢💢💢💢
‍ import cv2
import numpy as np

img = cv2.imread('coins.jpg')
coins_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

coins_preprocessed = cv2.GaussianBlur(coins_gray, (5, 5), 0)
_, coins_binary = cv2.threshold(coins_preprocessed, 130, 255, cv2.THRESH_BINARY)
coins_binary = cv2.bitwise_not(coins_binary)

_,coins_contours, _ = cv2.findContours(coins_binary, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

# make copy of image
coins_and_contours = np.copy(img)

# find contours of large enough area
min_coin_area = 60
large_contours = [cnt for cnt in coins_contours if cv2.contourArea(cnt) > min_coin_area]

# draw contours
cv2.drawContours(coins_and_contours, large_contours, -1, (255,0,0))

# print number of contours

print('number of coins: %d' % len(large_contours))
# create copy of image to draw bounding boxes
bounding_img = np.copy(img)

# for each contour find bounding box and draw rectangle
for contour in large_contours:
x, y, w, h = cv2.boundingRect(contour)
cv2.rectangle(bounding_img, (x, y), (x + w, y + h), (0, 255, 0), 3)
cv2.namedWindow('image', cv2.WINDOW_NORMAL)
cv2.imshow('image', bounding_img)
cv2.waitKey(0)
cv2.destroyAllWindows()
💢💢💢💢💢
python_developer
‍ import cv2 def sufra(): img = cv2.imread('coins.jpg') coins_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) cv2.namedWindow('image', cv2.WINDOW_NORMAL) coins_preprocessed = cv2.GaussianBlur(coins_gray, (5, 5), 0) _, coins_binary = cv2.threshold(coins_preprocessed…
⁉️اگر کد منتخب ارر داد کد زیر را امتحان کنید:
import cv2


def sufra():
img = cv2.imread('coins.jpg')
coins_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
cv2.namedWindow('image', cv2.WINDOW_NORMAL)
coins_preprocessed = cv2.GaussianBlur(coins_gray, (5, 5), 0)
_, coins_binary = cv2.threshold(coins_preprocessed, 130, 255, cv2.THRESH_BINARY)
coins_binary = cv2.bitwise_not(coins_binary)
cv2.namedWindow('image', cv2.WINDOW_NORMAL)
cv2.imshow('image', coins_binary)
cv2.waitKey(0)
cv2.destroyAllWindows()


if name == 'main':
sufra()
💢دومین پروژه💢
2) تشخیص چهره
تشخیص چهره یکی از داغترین موضوعات بینایی کامپیوتر در چند سال اخیر بوده است.
این تکنولوژی قابل استفاده و همه جا در دسترس است.
در همین ابتدا سه مفهوم زیر را به خاطر بسپارید:
💡1️⃣:مفهموم Face detection: تشخیص چهره واینکه مورد مربوط به چهره یک فرد باشد.
💡2️⃣:مفهومFace recognition: تشخیص یا شناخت چهره یک فرد خاص مثلا علی.
💡3️⃣:مفهوم facial expression recignition:تشخیص حالت چهره ، اینکه یه فردی خوشحاله یا غمگینه و....

💢💢💢💢💢
احتمالا در این پروژه ، اول face detectionو سپس face recognition را با استفاده از opencv مورد بحث قرار دهیم.

💢💢💢