Color detection & tracking

inRange

$ cv2.inRange(image, lower, upper)

Parameter:

  • image => ภาพที่ต้องการนำมาใช้

  • lower => ค่าสีต่ำสุดที่ต้องการ โดยเขียนในลักษณะ tuple BGR

  • upper => ค่าสีสูงสุดที่ต้องการ โดยเขียนในลักษณะ tuple BGR

Example:

import numpy as np
import cv2

image = cv2.imread("path/your/image.jpg")

colors = [
	([17, 15, 100], [50, 56, 200]),
	([86, 31, 4], [220, 88, 50]),
	([25, 146, 190], [62, 174, 250]),
	([103, 86, 65], [145, 133, 128])
]


for (lower, upper) in colors:

	lower = np.array(lower, dtype = "uint8")
	upper = np.array(upper, dtype = "uint8")

	mask = cv2.inRange(image, lower, upper)
	output = cv2.bitwise_and(image, image, mask = mask)
	
	cv2.imshow("images", np.hstack([image, output]))
	cv2.waitKey(0)

tracking

tracking จะเป็นเทคนิคที่ใช้ในการติดตามวัตถุที่อยู่บนภาพวิดีโอหรือการแสดงภาพแบบ Real-time โดยในหัวข้อนี้จะเป็นการติดตามวัตถุที่มีสีตามที่ผู้ใช้กำหนด

  • รับภาพที่เป็นวิดีโอหรือภาพจากกล้อง webcam

  • กำหนดค่าสีที่ต้องการใช้งาน

  • color detection

  • contour

Example:

Last updated

Was this helpful?