|
In this example we captured a series of JPEG images from a camera aimed at a traffic scene. Using the first frame as the reference, we analyzed each image by comparing it to the reference and calculated the correlation coefficient. The individual frames and their coefficients are shown at left.
We can see that for the frames with no vehicles shown the correlations to the reference image are very high: .96 and .97. But when a car begins to enter the scene, as in Test Frame4 the value dips to .94. Test Frame1 shows a dark vehicle in the far lane and the value drops to .91. And in Frame8 the value dramatically declined to .78 when a car begins to enter the scene in the near lane. This can be an efficient method for automatically screening video frames for scene changes. The suspect frames can then be analyzed visually or with image processing techniques. The applications can include detecting motion with security cameras, finding a matching image, and quality control. The procedure is:
VB Source Code Detect Scene Change - the Visual Basic Source CodeRequires Victor Image Processing Library for 32-bit Windows v 5.4 or higher and the helper dll vicstats.dll.
' Function Declarations and Data Type Definitions are in vic32def.bas
' see the Victor Library sample VB applications Loadpic or Comparator
' The Function ....................................................
Private Sub mnudetectscenechange_Click()
Dim rcode As Long
Dim sourceimage As imgdes ' Image descriptor for the reference image
Dim operatorimage As imgdes ' Image descriptor for the test image
Dim tempimage As imgdes ' Just in case we have to convert test image to same pixel depth as the reference image
Dim filedata As JpegData
Dim srcbpp As Long
Dim coef As Double ' Correlation Coefficient
Dim resultstr As String
' Get the image dimensions from the first file
rcode = jpeginfo("p1a.jpg", filedata)
If (rcode = NO_ERROR) Then
' Allocate an image buffer to hold the image
rcode = allocimage(sourceimage, filedata.width, filedata.length, filedata.vbitcount)
If (rcode = NO_ERROR) Then
' Load the image from the file
rcode = loadjpg("p1a.jpg", sourceimage)
If (rcode = NO_ERROR) Then ' Successfully loaded the reference image
srcbpp = filedata.vbitcount
' Get the image dimensions from the second file
rcode = jpeginfo("p3a.jpg", filedata)
If (rcode = NO_ERROR) Then
' Allocate an image buffer to hold the image
rcode = allocimage(operatorimage, filedata.width, filedata.length, filedata.vbitcount)
If (rcode = NO_ERROR) Then
' Load the image from the file
rcode = loadjpg("p3a.jpg", operatorimage)
If (rcode = NO_ERROR) Then
' Test for pixel depth
If (filedata.vbitcount <> srcbpp) Then ' If it's not compatible pixel depth
' Allocate the temporary image buffer
rcode = allocimage(tempimage, filedata.width, filedata.length, srcbpp)
If (rcode = NO_ERROR) Then
If (srcbpp = 24) Then
' Convert 8-bit grayscale to rgb color
rcode = convertpaltorgb(operatorimage, tempimage)
Else
' Convert 24-bit color to 8-bit grayscale
rcode = colortogray(operatorimage, tempimage)
End If
If (rcode = NO_ERROR) Then
' Replace the original operator image with the converted image
freeimage operatorimage
copyimgdes tempimage, operatorimage
End If
End If
End If
' Now do the analysis
rcode = correlationcoef(sourceimage, operatorimage, coef)
freeimage operatorimage
End If
End If
End If
freeimage sourceimage
End If
End If
End If
resultstr = "Result of analysis:" + Chr(13)
resultstr = resultstr + "rcode = " + Str(rcode) + Chr(13)
If (rcode = NO_ERROR) Then
resultstr = resultstr + "Correlation Coefficient = " + Str(coef) + Chr(13)
End If
MsgBox resultstr
End Sub
|
Victor Image Processing Library homepage | Victor Product Summary | more source code