Coin counting
ภาพตัวอย่าง

step 1 : เปิด terminal (windows - cmd , mac - terminal)
step 2 : เข้าโฟลเดอร์ที่ติดตั้ง Visual environment และไลบารี่ OpenCV
step 3 : เปิด Visual environment
step 4 : command “code .” in terminal

step 5 : create file counter.py
step 6 : ลำดับการทำงานของชุดคำสั่ง
นับเฉพาะเหรียญ หมายความว่า ต้องทำการแยกวัตถุกับภาพพื้นหลังออกจากกัน ก็คือใช้ Threshold แต่เนื่องจาก Threshold ต้องใช้กับภาพไบนารีหรือภาพสีเทาเท่านั้น หลังจากได้ภาพไบนารีที่มีแต่เหรียญได้แล้ว จากนั้นจึงทำการวาดกรอบรอบเหรียญเพื่อทำการนับ หรือก็คือการใช้ Contour
รับภาพ
cv2.imreadเปลี่ยนภาพเป็นสีเทา
cv2.cvtColorเบลอภาพเพื่อลด noise
cv2.GaussianBlurthreshold
cv2.thresholdcontour
cv2.findContour & cv2.drawContoursแสดงเลขตรงจุดกึ่งกลางของเหรียญ
cv2.moment & cv2.putText
step 7 : save file and run "python counter.py" on terminal

Example:

Last updated
Was this helpful?