read()
if not grabbed:
raise ValueError("Camera read failed!")
bg = utils.image_resize(frame, height=600).astype(np.float32)
while True:
grabbed, frame = camera.read()
if not grabbed:
print "Camera read failed"
break
if not calibrated:
# Sample hand color
utils.add_text(frame, "Press space after covering rectangle with hand. Hit SPACE when ready")
x, y, w, h = width / 4, height / 2, 50, 50
else:
cv2.accumulateWeighted(frame, bg, 0.01) MK: Image Processing
010100010010101010000100010100101010010100010001001101010010010101010
010100010010101010000100010101001001101010100100100101010
grabbed, frame = camera.read()
if not grabbed:
raise ValueError("Camera read failed!")
Pendahuluan
bg = utils.image_resize(frame, height=600).astype(np.float32)
while True:
grabbed, frame = camera.read()
if not grabbed:
print "Camera read failed"
break
Simple Thresholding
bg = utils.image_resize(frame, height=600).astype(np.float32)
while True:
grabbed, frame = camera.read()
if not grabbed:
print "Camera read failed"
break
Style Thresholding
bg = utils.image_resize(frame, height=600).astype(np.float32)
while True:
grabbed, frame = camera.read()
if not grabbed:
print "Camera read failed"
break
• cv2.THRESH_BINARY_INV
• cv2.THRESH_TRUNC
• cv2.THRESH_TOZERO
Binary Thresholding
bg = utils.image_resize(frame, height=600).astype(np.float32)
while True:
grabbed, frame = camera.read()
if not grabbed:
print "Camera read failed"
break
• Fungsi cv2.THRESH_BINARY
• Contoh sintaks
ret,thresholding = cv2.threshold(gray,127,255,cv2.THRESH_BINARY)
Binary Thresholding
bg = utils.image_resize(frame, height=600).astype(np.float32)
while True:
grabbed, frame = camera.read()
if not grabbed:
print "Camera read failed"
break
Binary Thresholding
bg = utils.image_resize(frame, height=600).astype(np.float32)
while True:
grabbed, frame = camera.read()
if not grabbed:
print "Camera read failed"
break
Binary_INV Thresholding
bg = utils.image_resize(frame, height=600).astype(np.float32)
while True:
grabbed, frame = camera.read()
if not grabbed:
print "Camera read failed"
break
• Fungsi cv2.THRESH_BINARY_INV
• Contoh sintaks
ret,thresholding = cv2.threshold(gray,127,255,cv2.THRESH_BINARY_INV)
Binary_INV Thresholding
bg = utils.image_resize(frame, height=600).astype(np.float32)
while True:
grabbed, frame = camera.read()
if not grabbed:
print "Camera read failed"
break
Binary_INV Thresholding
bg = utils.image_resize(frame, height=600).astype(np.float32)
while True:
grabbed, frame = camera.read()
if not grabbed:
print "Camera read failed"
break
TRUNC Thresholding
bg = utils.image_resize(frame, height=600).astype(np.float32)
while True:
grabbed, frame = camera.read()
if not grabbed:
print "Camera read failed"
break
• Fungsi cv2.THRESH_BINARY_INV
• Contoh sintaks
ret,thresholding = cv2.threshold(gray,127,255,cv2.THRESH_TRUNC)
TRUNC Thresholding
bg = utils.image_resize(frame, height=600).astype(np.float32)
while True:
grabbed, frame = camera.read()
if not grabbed:
print "Camera read failed"
break
TRUNC Thresholding
bg = utils.image_resize(frame, height=600).astype(np.float32)
while True:
grabbed, frame = camera.read()
if not grabbed:
print "Camera read failed"
break
TOZERO Thresholding
bg = utils.image_resize(frame, height=600).astype(np.float32)
while True:
grabbed, frame = camera.read()
if not grabbed:
print "Camera read failed"
break
• Fungsi cv2.THRESH_BINARY_INV
• Contoh sintaks
ret,thresholding = cv2.threshold(gray,127,255,cv2.THRESH_TOZERO)
TOZERO Thresholding
bg = utils.image_resize(frame, height=600).astype(np.float32)
while True:
grabbed, frame = camera.read()
if not grabbed:
print "Camera read failed"
break
TOZERO Thresholding
bg = utils.image_resize(frame, height=600).astype(np.float32)
while True:
grabbed, frame = camera.read()
if not grabbed:
print "Camera read failed"
break
TOZERO_INV Thresholding
bg = utils.image_resize(frame, height=600).astype(np.float32)
while True:
grabbed, frame = camera.read()
if not grabbed:
print "Camera read failed"
break
• Fungsi cv2.THRESH_BINARY_INV
• Contoh sintaks
ret,thresholding = cv2.threshold(gray,127,255,cv2.THRESH_TOZERO_INV)
TOZERO_INV Thresholding
bg = utils.image_resize(frame, height=600).astype(np.float32)
while True:
grabbed, frame = camera.read()
if not grabbed:
print "Camera read failed"
break
TOZERO_INV Thresholding
bg = utils.image_resize(frame, height=600).astype(np.float32)
while True:
grabbed, frame = camera.read()
if not grabbed:
print "Camera read failed"
break
Adaptive Thresholding
bg = utils.image_resize(frame, height=600).astype(np.float32)
while True:
grabbed, frame = camera.read()
if not grabbed:
print "Camera read failed"
break
• Dengan menggunakan nilai threshold global mungkin bukan pilihan yang baik
karena gambar memiliki kondisi pencahayaan yang berbeda di area yang berbeda.
• Dalam hal ini, mencari nilai threshold adaptif. Sehingga mendapatkan batasan yang
berbeda untuk berbagai wilayah dengan citra yang sama dan memberi hasil yang
lebih baik untuk citra dengan iluminasi yang bervariasi.
• Metode Adaptive Thresholding yang dapat digunakan untuk menghitung nilai
threshold :
• cv2.ADAPTIVE_THRESH_MEAN_C : nilai ambang batas adalah rata-rata area lingkungan pada
gambar.
• cv2.ADAPTIVE_THRESH_GAUSSIAN_C : nilai ambang adalah jumlah tertimbang nilai
lingkungan dimana bobot adalah window gaussian.
Adaptive Thresholding
bg = utils.image_resize(frame, height=600).astype(np.float32)
while True:
grabbed, frame = camera.read()
if not grabbed:
print "Camera read failed"
break
Adaptive Thresholding
bg = utils.image_resize(frame, height=600).astype(np.float32)
while True:
grabbed, frame = camera.read()
if not grabbed:
print "Camera read failed"
break
Otsu’s Binarization
bg = utils.image_resize(frame, height=600).astype(np.float32)
while True:
grabbed, frame = camera.read()
if not grabbed:
print "Camera read failed"
break
Otsu’s Binarization
bg = utils.image_resize(frame, height=600).astype(np.float32)
while True:
grabbed, frame = camera.read()
if not grabbed:
print "Camera read failed"
break
Otsu’s Binarization
bg = utils.image_resize(frame, height=600).astype(np.float32)
while True:
grabbed, frame = camera.read()
if not grabbed:
print "Camera read failed"
break
while True:
grabbed, frame = camera.read()
if not grabbed:
print "Camera read failed"
break