วันศุกร์ที่ 16 ธันวาคม พ.ศ. 2559

OPENCV : 7. Color Detection & Object Tracking
















*******************************************************************

อธิบายโค้ด

- HSV ประกอบไปด้วย 3 matrics คือ Hue , SATURATION  และ VALUE
   - hue มีค่าตั้งแต่ 0 - 179                  ใช้สำหรับเพื่อ แยกสี
   - saturation มีค่าตั้งแต่ 0 - 255         ใช้สำหรับเพื่อ แยกแสง
   - value มีค่าตั้งแต่ 0 - 255                ใช้สำหรับเพื่อ แยกแสง



- หลังจาก threshold image เราจะเจอ object สีขาวบางแห่ง  ในที่ต่างๆ  ซึงเราสามารถกำจัดสีขาวที่ไม่จำเป็น
ได้โดย  morphological opening

- Morphological opening ทำได้โดยการ erosion แล้วตามด้วย dilation ด้วย structuring element ขนาดเดียวกัน

- หลังจาก threshold image เราจะเจอ object สีขาวบางแห่ง  ใน object ที่เราสนใจ  ซึงเราสามารถกำจัดสีขาวที่ไม่จำเป็น
ได้โดย  morphological closing

- Morphological closing ทำได้โดยการ dilation แล้วตามด้วย erosion ด้วย structuring element ขนาดเดียวกัน


- void inRange( InputArray src, InputArray lowerb, InputArray upperb, OutputArray dst);
  ถ้า lowerb เป็น Scalar(x, y, z) พิกเซลที่มีค่าน้อยกว่า x , y และ z    สำหรับ hsv แล้ว มันจะมี่ค่าเป็น 0
  ซึ่งก็คือ สีดำ 

  ถ้า upperb เป็น Scalar(x, y, z) พิกเซลที่มีค่ามากกว่า x , y และ z    สำหรับ hsv แล้ว มันจะมี่ค่าเป็น 255
  ซึ่งก็คือ สีขาว



- Moments moments( InputArray array, bool binaryImage=false )
 อินพุต array คือ image ที่ต้องเป็น single chanel

 0th order central moments of the binary image is equal to the white area of the image in pixels.
  • X coordinate of the position of the center of the object  =  1st order spatial moment around x-axis /  0th order central moment
  • Y coordinate of the position of the center of the object  =  1st order spatial moment around y-axis / 0th order central moment


- static MatExpr zeros(Size size, int type)
  จะให้เป็น ภาพสีดำ

ไม่มีความคิดเห็น:

แสดงความคิดเห็น