Menu

Tuesday, October 8, 2013

[EmguCV] วิธีการสร้างภาพพื้นหลังจากชุดของภาพ
[EmguCV] How to Create Background Image from a series of images

ในกรณีนี้ กล้องถ่ายภาพจำเป็นต้องถูกยึดอยู่กับที่
In this case, a camera must be stationary. 

นั่นหมายความว่า ภาพพื้นหลังจะเหมือนกันทุกภาพ ในขณะที่วัตถุจะมีการปรากฏขึ้นเพียงบางภาพเท่านั้น
That mean background are the same for each image while objects (foreground) will appear in only few images. 

ดังนั้น ภาพพื้นหลังสามารถสร้างได้ โดยการเฉลี่ยชุดของภาพ
Therefore, background can be created by averaging a series of images.

ใน EmguCV, RunningAvg สามารถถูกเรียกใช้ เพื่อสร้างภาพพื้นหลังดังกล่าว
In EmguCV, RunningAvg can be called to do that

สมมติว่า capture เป็นออบเจ็คต์ประเภท Capture ซึ่งสามารถอ่านภาพได้จากกล้องหรือจากไฟล์วิดีโอ
Assume that capture is a Capture object which can be a capture from camera or from video file.

โค้ดด้านล่างเป็นตัวอย่างการเรียกใช้ RunningAvg
The below code is an example of using RunningAvg 
  1. Image<Bgr, byte> frame = capture.QueryFrame();
  2. Image<Bgr, float> image_float;
  3. Image<Bgr, float> background= new Image<Bgr, float>(frame.Size);
  4. background.SetZero();

  5. double avg_ratio = 0.003;

  6. while (frame != null)
  7. {
  8.      image_float = frame.Convert<Bgr, float>();
  9.      background.RunningAvg(image_float, avg_ratio);
  10.      frame = capture.QueryFrame();
  11. }

background เป็นภาพเฉลี่ยที่สามารถใช้เป็นภาพพื้นหลังสำหรับการลบภาพพื้นหลังได้
background is an average image that can be used as the background image for background subtraction

No comments:

Post a Comment