Cài đặt một số phương pháp phát hiện và đánh dấu đối tượng

Một phần của tài liệu Nghiên cứu một số phương pháp phát hiện chuyển động trong video và ứng dụng (Trang 53)

3.2.1. Giao diện của chương trình

3.2.2. Các menu

Hình 3.2: Menu File

Menu này bao gồm các chức năng để mở các video từ một file AVI, từ một file AVI trên mạng internet, từ camera gắn trực tiếp với máy tính.

Hình 3.3: Menu Motion

Hình 3.4: Ảnh nền

3.2.3. Một số hình ảnh về phát hiện và đánh dấu đối tượng chuyển động chuyển động

Hình 3.7: Phát hiện và đánh dấu đối tượng theo biên

Hình 3.8: Phát hiện và đánh dấu đối tượng bằng cách đóng khung đối tượng chuyển động trong một hình chữ nhật

KẾT LUẬN

Như ta đã biết, giám sát bằng camera được ứng dụng rộng rãi trong nhiều lĩnh vực của cuộc sống, việc nghiên cứu các vấn đề liên quan đến các hệ thống giám sát này nhằm đưa ra các cảnh báo chính xác, kịp thời là một công việc mang tính thực tiễn cao. Chúng ta cũng biết rằng kết quả thu nhận được từ các camera giám sát là video. Như vậy việc nghiên cứu chính ở đây là phát hiện đối tượng chuyển động trong video.

Video thu nhận được từ các camera sẽ được xử lý qua các công đoạn sau: Phát hiện đối tượng chuyển động, đánh dấu các đối tượng vừa phát hiện, phân loại chúng và đem so sánh với cơ sở dữ liệu mẫu, nếu khớp thì sẽ đưa ra các cảnh báo tương ứng, nếu chưa khớp thì sẽ có bước phán đoán và sau đó tiếp tục cập nhật các đối tượng này vào kho dữ liệu mẫu. Như vậy, theo thời gian, kho dữ liệu mẫu càng phong phú và đầy đủ hơn.

Trong phạm vi luận văn này, tôi đã nghiên cứu và trình bày lại một số phương pháp phát hiện đối tượng và một số bước hậu xử lý để làm cho đối tượng vừa được phát hiện rõ ràng hơn, tránh các trường hợp phát hiện nhầm do nhiễu. Sau khi phát hiện đối tượng, sẽ chuyển sang bước đánh dấu và phân loại đối tượng chuyển động.

Sau khi nghiên cứu các phương pháp đó, sẽ tìm ra phần ưu, phần nhược của từng phương pháp, từ đó có bước kết hợp giữa các phương pháp hoặc đưa ra các giải pháp để khắc phục các nhược điểm nhằm xây dựng một hệ thống giám sát tối ưu nhất có thể.

Trong luận văn này tôi cũng đã cài đặt thành công một số phương pháp phát hiện và đánh dấu đối tượng chuyển động. Hệ thống đầu vào trong bản demo này là lấy hình ảnh trực tiếp từ camera gắn vào máy tính, lấy một file video có phần đặc trưng là AVI từ nguồn có sẵn hoặc các video lấy từ nguồn trực tuyến.

Hướng nghiên cứu sâu hơn của đề tài này mà tôi quan tâm đó là phát hiện và phân loại từng phần chuyển động của đối tượng, từ đó xây dựng các ứng dụng hỗ trợ cho con người. Một hướng khác nữa là tìm hiểu rõ về đặc điểm của lửa, từ đó xây dựng các hệ thống cảnh báo hỏa hoạn.

TÀI LIỆU THAM KHẢO

[1] J.K. Aggarwal and Q. Cai. Human motion analysis: A review. Computer Vision and Image Understanding, March 1999.

[2] A. Amer. Voting-based simultaneous tracking of multiple video objects. In Proc. SPIE Int. Symposium on Electronic Imaging, Santa Clara, USA, January 2003. [3] E.M. Arkin, L.P. Chew, D.P. Huttenlocher, K. Kedem, and J.S.B. Mitchell. An

efficiently computable metric for comparing polygonal shapes. IEEE Transactions on Pattern Recognition and Machine Intelligence, 1991.

[4] R. Bodor, B. Jackson, and N. Papanikolopoulos. Vision-based human tracking and activity recognition. In Proc. of the 11th Mediterranean Conf. on Control and Automation, June 2003.

[5] A. Cavallaro and F. Ziliani. Image Analysis for Advanced Video Surveillance, Multimedia Video-Based Surveillance Systems, Kluwer Academic Publishers, Boston, 2000.

[6] H.T. Chen, H.H. Lin, and T.L. Liu. Multi-object tracking using dynamical graph matching. In Proc. of IEEE Computer Society Conference on Computer Vision and Pattern Recognition, 2001.

[7] R. T. Collins, R. Gross, and J. Shi. Silhouette-based human identification from body shape and gait. In Proc. of Fifth IEEE Conf. on Automatic Face and Gesture Recognition, 2002.

[8] R. Cutler and L.S. Davis. Robust real-time periodic motion detection, analysis and applications. In IEEE Transactions on Pattern Analysis and Machine Intelligence, 2000.

[9] A. Elgammal, R. Duraiswami, D. Harwood, and L. S. Davis. Background and foreground modeling using non-parametric kernel density estimation for visual surveillance. In Proc. of the IEEE, 2002.

[10] R. T. Collins et al. A system for video surveillance and monitoring: VSAM final report. Technical report CMU-RI-TR-00-12, Robotics Institute, Carnegie Mellon University, May 2000.

[11] T. Brodsky et al. Visual Surveillance in Retail Stores and in the Home, Boston, 2002.

[12] H. Fujiyoshi and A.J. Lipton. Real time human motion analysis by image skeletonization. In Proc. of Workshop Applications of Computer Vision, 1998.

[13] D. M. Gavrila. The analysis of human motion and its application for visual surveillance. In Proc. of the 2nd IEEE International Workshop on Visual Surveillance, Fort Collins, U.S.A., 1999.

[14] D. Greenhill, P. Remagnino, and G. A. Jones. VIGILANT, Video-Based Surveillance Systems. Kluwer Academic Publishers, Boston, 2002. (adsbygoogle = window.adsbygoogle || []).push({});

[15] I. Haritaoglu. A Real Time System for Detection and Tracking of People and Recognizing Their Activities, University of Maryland at College Park, 1998. [16] I. Haritaoglu, R. Cutler, D. Harwood, and L. S. Davis. Backpack: Detection of

people carrying objects using silhouettes. Computer Vision and Image Understanding, 2001.

[17] I. Haritaoglu, D. Harwood, and L.S. Davis. W4: A real time system for detecting and tracking people. In Computer Vision and Pattern Recognition, 1998.

[18] G. Healey, D. Slater, T. Lin, B. Drda, and D. Goedeke. A system for real-time fire detection. Computer Vision and Pattern Recognition, 1993.

[19] F. Heijden. Image Based Measurement Systems: Object Recognition and Parameter Estimation. Wiley, January 1996.

[20] J. Heikkila and O. Silven. A real-time system for monitoring of cyclists and pedestrians. In Proc. of Second IEEE Workshop on Visual Surveillance, Fort Collins, Colorado, June 1999.

[21] T. Horprasert, D. Harwood, and L.S. Davis. A statistical approach for realtime robust background subtraction and shadow detection. In Proc. of IEEE Frame Rate Workshop, Greece, 1999.

[22] H.Ramoser, T.Schlgl, M.Winter, and H.Bischof. Shape-based detection of humans for video surveillance. In Proc. of IEEE Int. Conf. on Image Processing,

Spain, 2003.

[23] W. Phillips III, M. Shah, and N. Da Vitoria Lobo. Flame recognition in video. In Fifth IEEE Workshop on Applications of Computer Vision, December 2000. [24] Y. Ivanov, C. Stauffer, A. Bobick, and W.E.L. Grimson. Video surveillance of

interactions. In International Workshop on Visual Surveillance, Fort Collins, Colorado, June 1999.

[25] S. Ju, M. Black, and Y. Yaccob. Cardboard people: a parameterized model of articulated image motion. In Proc. of the IEEE International Conference on Automatic Face and Gesture Recognition, 1996.

[26] P. KaewTraKulPong and R. Bowden. An Improved Adaptive Background Mixture Model for Real-time Tracking with Shadow Detection, Boston, 2002.

[27] S. Khan and M. Shah. Tracking people in presence of occlusion. In Proc. of Asian Conference on Computer Vision, Taiwan, January 2000.

[28] A. J. Lipton. Local application of optic flow to analyse rigid versus non-rigid motion. Technical Report CMU-RI-TR-99-13, Robotics Institute, Carnegie

Mellon University, Pittsburgh, PA, December 1999.

[29] A. J. Lipton, H. Fujiyoshi, and R.S. Patil. Moving target classification and tracking from real-time video. In Proc. of Workshop Applications of Computer Vision, 1998.

[30] C. B. Liu and N. Ahuja. Vision based fire detection. In IEEE International Conference on Pattern Recognition, Cambridge, UK, August 2004. to appear. [31]

S. Loncaric. A survey of shape analysis techniques. Pattern Recognition, August 1998.

[32] D. R. Magee. Tracking multiple vehicles using foreground, background and motion models. In Proc. of Statistical Methods in Video Processing Workshop, June 2002.

[33] J. S. Marques, P. M. Jorge, A. J. Abrantes, and J. M. Lemos. Tracking groups of pedestrians in video sequences. In Proc. of IEEE Workshop on Multi-Object Tracking, Madison, June 2003.

[34] A. M. McIvor. Background subtraction techniques. In Proc. of Image and Vision Computing, New Zealand, 2000.

[35] S.J. McKenna, S. Jabri, Z. Duric, and H. Wechsler. Tracking interacting people. In Proc. of International Conference on Automatic Face and Gesture Recognition, 2000.

[36] F. Oberti, G. Ferrari, and C. S. Regazzoni. A Comparison between Continuous and Burst, Recognition Driven Transmission Policies in Distributed BIBLIOGRAPHY 84 3GSS, Boston, 2002.

[37] J. Owens and A. Hunter. A fast model-free morphology-based object tracking algorithm. In Proc. of British Machine Vision Conference, UK, September 2002. [38] C. Papageorgiou, T. Evgeniou, and T. Poggio. A trainable pedestrian detection

system. In Proc. of IEEE Int. Conf. on Intelligent Vehicles, Germany, October 1998.

[39] C. Regazzoni and P. Varshney. Multi-sensor surveillance. In IEEE Int. Conf. Image Processing, 2002.

[40] R. Rosales and S. Sclaroff. Improved tracking of multiple humans with trajectory prediction and occlusion modeling. In Proc. of IEEE CVPR Workshop on the Interpretation of Visual Motion, CA, 1998.

[41] M. Saptharishi, J.B. Hampshire II, and P. Khosla. Agent-based moving object correspondence using differential discriminative diagnosis. In Proc. Of Computer Vision and Pattern Recognition, 2000.

[42] E. Saykol, U. Gudukbay, and O. Ulusoy. A histogram-based approach for object- based query-by-shape-and-color in multimedia databases. Technical Report BUCE-0201, Bilkent University, 2002. (adsbygoogle = window.adsbygoogle || []).push({});

[43] E. Saykol, G. Gulesir, U. Gudukbay, and O. Ulusoy. KiMPA: A kinematicsbased method for polygon approximation. In International Conference on Advances in Information Systems, Turkey, 2002.

[44] C. Stauffer and W. Grimson. Adaptive background mixture models for realtime tracking. In Proc. of the IEEE Computer Society Conference on Computer Vision and Pattern Recognition, 1999.

[45] C. Stauffer and W.E.L. Grimson. Learning patterns of activity using real-time tracking. IEEE Pattern Recognition and Machine Intelligence, August 2000. [46] B. U. Toreyin. Moving object detection and tracking in wavelet compressed

video. Master’s thesis, Bilkent University, 2003.

[47] R.C. Veltkamp and M. Hagedoorn. State-of-the-art in shape matching, pages 87– 119. Principles of Visual Information Retrieval. Springer, 2001.

[48] H. Wang and S.F. Chang. Automatic face region detection in mpeg video sequences. In Electronic Imaging and Multimedia Systems, China, November 1996.

[49] L. Wang, W. Hu, and T. Tan. Recent developments in human motion analysis, March 2003.

[50] L. Wang, H. Ning, T. Tan, and W. Hu. Fusion of static and dynamic features of body biometrics for gait recognition. In Proc. of International Conference on Computer Vision, France, 2003.

[51] L. Wixson and A. Selinger. Classifying moving objects as rigid or non-rigid. In Proc. of DARPA Image Understanding Workshop, 1998.

[52] C. R. Wren, A. Azarbayejani, T. J. Darrell, and A. P. Pentland. Pfinder: Real-time tracking of the human body. IEEE Pattern Recognition and Machine Intelligence, July 1997.

[53] M. Xu and T. Ellis. Colour-Invariant Motion Detection under Fast Illumination Changes, Boston, 2002.

[54] T. Zhao, R. Nevatia, and F. Lv. Segmentation and tracking of multiple humans in complex situations. In Proc. of USC Computer Vision, 2001.

[55] X. Zhou, R. T. Collins, T. Kanade, and P. Metes. A master-slave system to acquire biometric imagery of humans at distance. In First ACM SIGMM International Workshop on Video Surveillance, ACM Press, 2003.

PHỤ LỤC

Một số mã lệnh phát hiện và đánh dấu đối tượng đặc trưng đã cài đặt được viết trền nền Microsoft Visual C#

Phát hiện đối tượng chuyển động bằng phương pháp khác biệt thời gian và đánh dấu đối tượng chuyển động bằng màu đỏ

namespace motion { using System; using System.Drawing; using System.Drawing.Imaging; using AForge.Imaging; using AForge.Imaging.Filters;

public class MotionDetector1 : IMotionDetector {

private IFilter grayscaleFilter = new GrayscaleBT709( );

private Difference differenceFilter = new Difference( ); private Threshold thresholdFilter = new Threshold( 15 );

private IFilter erosionFilter = new Erosion( );

private Merge mergeFilter = new Merge( );

private IFilter extrachChannel = new ExtractChannel( RGB.R );

private ReplaceChannel replaceChannel = new ReplaceChannel( RGB.R, null );

private Bitmap backgroundFrame; private BitmapData bitmapData;

private bool calculateMotionLevel = false;

private int width; // image width

private int height; // image height

private int pixelsChanged;

// Buoc tinh toan chuyen dong hoac khong chuyen dong (adsbygoogle = window.adsbygoogle || []).push({});

public bool MotionLevelCalculation {

get { return calculateMotionLevel; }

set { calculateMotionLevel = value; } }

// So luong cac thay doi theo phan tram

public double MotionLevel {

get { return (double) pixelsChanged / ( width * height ); }

}

// Buoc xay dung

public MotionDetector1( ) {

}

// Dat lai phat hien cho trang thai khoi tao

public void Reset( ) { if ( backgroundFrame != null ) { backgroundFrame.Dispose( ); backgroundFrame = null; } } // Xu ly frame moi

public void ProcessFrame( ref Bitmap image ) {

if ( backgroundFrame == null ) {

// Tao anh nen khoi tao

backgroundFrame = grayscaleFilter.Apply( image );

// Lay kich thuoc cua anh

width = image.Width;

height = image.Height;

// chi tra ve cho lan dau tien

return; }

Bitmap tmpImage;

// Ap dung cho muc xam cua anh

tmpImage = grayscaleFilter.Apply( image );

differenceFilter.OverlayImage = backgroundFrame; Bitmap tmpImage2 = differenceFilter.Apply( tmpImage );

// Chot anh theo thoi gian va ap dung mot cach loc tren co so du lieu chot

bitmapData = tmpImage2.LockBits( new Rectangle( 0, 0, width, height ),

ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed ); // loc threshold

thresholdFilter.ApplyInPlace( bitmapData ); // loc erosion

Bitmap tmpImage3 = erosionFilter.Apply( bitmapData ); //Huy chot (adsbygoogle = window.adsbygoogle || []).push({});

tmpImage2.UnlockBits( bitmapData ); tmpImage2.Dispose( );

// Tinh toan so luong cac pixel da thay doi

pixelsChanged = ( calculateMotionLevel ) ? CalculateWhitePixels( tmpImage3 ) : 0;

// Giai phong nen cu

backgroundFrame.Dispose( );

// dat nen lam nen hien thoi

backgroundFrame = tmpImage;

// Trich rut mau do tu anh goc

Bitmap redChannel = extrachChannel.Apply( image );

// Tron mau do voi doi tuong chuyen dong

mergeFilter.OverlayImage = tmpImage3;

Bitmap tmpImage4 = mergeFilter.Apply( redChannel ); redChannel.Dispose( );

tmpImage3.Dispose( );

// Thay goi mau do trong anh goc

replaceChannel.ChannelImage = tmpImage4;

Bitmap tmpImage5 = replaceChannel.Apply( image ); tmpImage4.Dispose( );

image.Dispose( ); image = tmpImage5; }

// Tinh toan cac diem anh trang

{

int count = 0;

// Khoa cac anh khac

BitmapData data = image.LockBits( new Rectangle( 0, 0, width, height ),

ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed );

int offset = data.Stride - width;

unsafe

{

byte * ptr = (byte *) data.Scan0.ToPointer( );

for ( int y = 0; y < height; y++ ) {

for ( int x = 0; x < width; x++, ptr++ ) { count += ( (*ptr) >> 7 ); } ptr += offset; } } // Huy khoa image.UnlockBits( data ); return count; } } }

Phát hiện đối tượng chuyển động và đánh dấu bằng đường viền xung quanh đối tượng (adsbygoogle = window.adsbygoogle || []).push({});

namespace motion { using System; using System.Drawing; using System.Drawing.Imaging; using AForge.Imaging; using AForge.Imaging.Filters;

public class MotionDetector3Optimized : IMotionDetector {

private byte[] backgroundFrame = null;

private byte[] currentFrame = null;

private byte[] currentFrameDilatated = null;

private int counter = 0;

private bool calculateMotionLevel = false;

private int width; // image width

private int height; // image height

private int pixelsChanged;

// Buoc tinh toan chuyen dong hoac khong chuyen dong

public bool MotionLevelCalculation {

get { return calculateMotionLevel; }

set { calculateMotionLevel = value; } }

// So luong cac thay doi theo phan tram

public double MotionLevel {

get { return (double) pixelsChanged / ( width * height ); } } // Phan chinh public MotionDetector3Optimized( ) { }

// Dat lai phat hien cho trang thai khoi tao

public void Reset( ) { backgroundFrame = null; currentFrame = null; currentFrameDilatated = null; counter = 0; } // Xu ly frame moi

public void ProcessFrame( ref Bitmap image ) {

// Lay kich co cua anh

width = image.Width; height = image.Height; int fW = ( ( ( width - 1 ) / 8 ) + 1 ); int fH = ( ( ( height - 1 ) / 8 ) + 1 ); int len = fW * fH; if ( backgroundFrame == null ) {

// Cap phat bo nho cho anh nen va anh hien thoi

backgroundFrame = new byte[len]; currentFrame = new byte[len];

currentFrameDilatated = new byte[len];

// khoa anh

BitmapData imgData = image.LockBits(

new Rectangle( 0, 0, width, height ), ImageLockMode.ReadOnly,

PixelFormat.Format24bppRgb );

// Tao anh nen khoi tao (adsbygoogle = window.adsbygoogle || []).push({});

PreprocessInputImage( imgData, width, height, backgroundFrame );

// Huy khoa

image.UnlockBits( imgData );

// Chi tra ve lan dau tien

return; }

// khoa anh

BitmapData data = image.LockBits(

new Rectangle( 0, 0, width, height ),

ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb );

// Xu ly anh dau vao

PreprocessInputImage( data, width, height, currentFrame );

if ( ++counter == 2 ) {

counter = 0;

// chuyen nen den frame hien thoi

for ( int i = 0; i < len; i++ ) {

int t = currentFrame[i] - backgroundFrame[i];

backgroundFrame[i]++;

else if ( t < 0 )

backgroundFrame[i]--; }

}

// su khac biet va nguong

pixelsChanged = 0;

for ( int i = 0; i < len; i++ ) {

int t = currentFrame[i] - backgroundFrame[i];

if ( t < 0 ) t = -t; if ( t >= 15 ) { pixelsChanged++; currentFrame[i] = (byte) 255; } else { currentFrame[i] = (byte) 0; } } if ( calculateMotionLevel ) pixelsChanged *= 64; else pixelsChanged = 0; // dan khung // No co the bi bo qua

for ( int i = 0; i < fH; i++ ) {

for ( int j = 0; j < fW; j++ ) {

int k = i * fW + j;

int v = currentFrame[k];

// cac diem anh trai (adsbygoogle = window.adsbygoogle || []).push({});

if ( j > 0 ) { v += currentFrame[k - 1]; if ( i > 0 ) { v += currentFrame[k - fW - 1]; } if ( i < fH - 1 ) { v += currentFrame[k + fW - 1]; } }

// cac diem anh phai

if ( j < fW - 1 ) { v += currentFrame[k + 1]; if ( i > 0 ) { v += currentFrame[k - fW + 1]; } if ( i < fH - 1 ) { v += currentFrame[k + fW + 1]; }

}

// diem anh dinh

if ( i > 0 ) {

v += currentFrame[k - fW]; }

// diem anh phai

if ( i < fH - 1 ) {

v += currentFrame[k + fW]; }

currentFrameDilatated[k] = (v != 0) ? (byte) 255 : (byte) 0; }

}

// Hau xu ly anh dau vao

PostprocessInputImage( data, width, height, currentFrameDilatated );

// Huy khoa anh

image.UnlockBits( data ); }

// Tien xu ly anh dau vao

private void PreprocessInputImage( BitmapData data, int width, int height,

byte[] buf ) {

int stride = data.Stride;

int offset = stride - width * 3;

int len = (int)( ( width - 1 ) / 8 ) + 1;

int rem = ( ( width - 1 ) % 8 ) + 1;

int[] tmp = new int[len];

int i, j, t1, t2, k = 0;

unsafe

{

byte * src = (byte *) data.Scan0.ToPointer( );

for ( int y = 0; y < height; ) {

// tap hop cac diem anh (adsbygoogle = window.adsbygoogle || []).push({});

Một phần của tài liệu Nghiên cứu một số phương pháp phát hiện chuyển động trong video và ứng dụng (Trang 53)