PDA

View Full Version : image processing with SonyXCD_SX910 camera



dinesh8_10
April 5, 2006, 07:47:53
Dear sir

i am working with SonyXCD_SX910 camera using VB6. my aim is to process the image data using its intensity values at various pixels according to centroid estimation algorithm. i placed rectangle as overlay to bring signal into desired processing area. the size of overlay rectangle is 300 x300 pixels. i want to find
pixel coordinate which have maxmum intnesity. please telll me about my approach to calculate brightest pixel coordinate ..whether it is right or wrong.....

one more thing u tell me the frame rate of this camera with resolution 640 x480...


code of image availbe function is following : .

global variable declaration
.................................................. ...........
Private DisplayBuffer As ImageBuffer
Private imagedata As Variant
Private coorx, coory As Integer
.................................................. ..............
Private Sub setupDevice()
' Set the color format to monochrome
ICImagingControl1.MemoryCurrentGrabberColorformat = ICY8
ICImagingControl1.ImageRingBufferSize = 30
ICImagingControl1.LiveCaptureContinuous = True
ICImagingControl1.LiveCaptureLastImage = False
ICImagingControl1.LiveDisplay = False
ICImagingControl1.OverlayBitmap.Enable = True

ICImagingControl1.OverlayBitmap.DrawFrameRect RGB(255, 255, 255), 50, 50, 350, 350
ICImagingControl1.OverlayBitmap.DrawLine RGB(255, 255, 255), 50, 200, 350, 200
ICImagingControl1.OverlayBitmap.DrawLine RGB(255, 255, 255), 200, 50, 200, 350
ICImagingControl1.OverlayBitmap.DrawLine RGB(255, 255, 255), 50, 50, 350, 350
ICImagingControl1.OverlayBitmap.DrawLine RGB(255, 255, 255), 50, 350, 350, 50

ICImagingControl1.OverlayBitmap.DrawText RGB(255, 255, 255), 10, 50, "50,50"
ICImagingControl1.OverlayBitmap.DrawText RGB(255, 255, 255), 360, 350, "350,350"
Set DisplayBuffer = ICImagingControl1.ImageBuffers.Item(1)
End Sub


' ICImagingControl1_ImageAvailable
Private Sub ICImagingControl1_ImageAvailable(ByVal BufferIndex As Long)
On Error GoTo err_ImageAvailableHandler
Dim x, y, max As Integer
Dim i, j As Long
Static t As Integer ' use for frame counter

Set DisplayBuffer = ICImagingControl1.ImageBuffers.Item(BufferIndex)
imagedata = DisplayBuffer.GetImageData

ICImagingControl1.OverlayBitmap.DrawText RGB(255, 255, 255), 300, 10, "Frame No." & t
max = imagedata(50, 50)

For y = 50 To 350
For x = 50 To 350
If max < imagedata(x, y) Then
max = imagedata(x, y)
coorx = x + 1
coory = y + 1
End If
Next x
Next y

Text10.Text = coorx ' for display of x coordinate of brightest pixel
Text11.Text = coory ' for display of y coordinate of brightest pixel
Text2.Text = max ' for display of value of brightest pixel

DisplayBuffer.ReleaseImageData imagedata

ICImagingControl1.DisplayImageBuffer DisplayBuffer
t = t + 1
err_ImageAvailableHandler:
Debug.Print Err.Description
End Sub
.................................................. .................................................. .........................


with regards

dinesh kumar meena

Stefan Geissler
April 5, 2006, 09:15:33
Hi Dinesh

The problem in your code is, that the overlay is painted in the live video. Thus the lines of your overlay are evaluated too. But the lines are the brightest points in the image. Thus the overlay in the display path should be used, not the overlay at the device or the sink. This results in the original image in the sink (displaybuffer) and drawings on the live video. Your sample should look like follows:


Private Sub Form_Load()
Dim OB As OverlayBitmap

With ICImagingControl1
.MemoryCurrentGrabberColorformat = ICY8
.ImageRingBufferSize = 30
.LiveCaptureContinuous = True
.LiveCaptureLastImage = False
.LiveDisplay = True

.OverlayBitmapPosition = PATHPOSITION_DISPLAY

.LiveStart

Set OB = .OverlayBitmapAtPath(PATHPOSITION_DISPLAY)

OB.Enable = True

OB.DrawFrameRect RGB(255, 255, 255), 50, 50, 350, 350
OB.DrawLine RGB(255, 255, 255), 50, 200, 350, 200
OB.DrawLine RGB(255, 255, 255), 200, 50, 200, 350
OB.DrawLine RGB(255, 255, 255), 50, 50, 350, 350
OB.DrawLine RGB(255, 255, 255), 50, 350, 350, 50

OB.DrawText RGB(255, 255, 255), 10, 50, "50,50"
OB.DrawText RGB(255, 255, 255), 360, 350, "350,350"
End With
End Sub

Private Sub ICImagingControl1_ImageAvailable(ByVal BufferIndex As Long)
On Error GoTo err_ImageAvailableHandler
Dim x, y, max As Integer
Dim i, j As Long
Static t As Integer ' use for frame counter
Dim DisplayBuffer As ImageBuffer


Set DisplayBuffer = ICImagingControl1.ImageBuffers.Item(BufferIndex)
imagedata = DisplayBuffer.GetImageData

ICImagingControl1.OverlayBitmap.DrawText RGB(255, 255, 255), 300, 10, "Frame No." & t
max = imagedata(50, 50)

For y = 50 To 350
For x = 50 To 350
If max < imagedata(x, y) Then
max = imagedata(x, y)
coorx = x + 1
coory = DisplayBuffer.FrameType.Height - y + 1
End If
Next x
Next y

Text10.Text = coorx ' for display of x coordinate of brightest pixel
Text11.Text = coory ' for display of y coordinate of brightest pixel
Text2.Text = max ' for display of value of brightest pixel

DisplayBuffer.ReleaseImageData imagedata

'ICImagingControl1.DisplayImageBuffer DisplayBuffer
t = t + 1
Exit Sub
err_ImageAvailableHandler:
Debug.Print Err.Description
End Sub

dinesh8_10
April 5, 2006, 11:20:13
Dear sir

Thank you for your kind correction. After calculating brightest pixel coordinate, i want to measure the center of mass of image using one standard formula..

x coordinate of center of mass is calculated as

‡”Ix,y.X/‡”Ix,y where Ix,y is intensity at coordinate (x,y)
and X is value of x coordinate

y coordinate of center of mass is calculated as

‡”Ix,y.Y/‡”Ix,y where Ix,y is intensity at coordinate (x,y)
and Y is value of x coordinate

after calculating center of mass for image, value of first image taken as refernce value... then calculate the center of mass of next image ... now calculate shift in center of mass using difference between reference and current center of mass... this differnce is multiplied by the pixel size of camera which is 4.65 micro meter in our case..this continue for next frame in continous mode .....

i write code for this one using code that u provide me in last query. please try to check it ... give ur comment .....

with regards
dinesh kumar meena
.................................................. .................................................. ............
Private imagedata As Variant
Private pix_x, pix_y, focal_length As Double
Private refcenx, refceny, cenx, ceny, shiftx, shifty As Double

Private Sub Form_Load()

Dim OB As OverlayBitmap

ICImagingControl1.ShowDeviceSettingsDialog

ICImagingControl1.Width = ICImagingControl1.ImageWidth
ICImagingControl1.Height = ICImagingControl1.ImageHeight
pix_x = 4.65 / 1000000
pix_y = 4.65 / 1000000
focal_length = 19.65 / 1000

With ICImagingControl1
.MemoryCurrentGrabberColorformat = ICY8
.ImageRingBufferSize = 30
.LiveCaptureContinuous = True
.LiveCaptureLastImage = False
.LiveDisplay = True
.OverlayBitmapPosition = PATHPOSITION_DISPLAY
.LiveStart

Set OB = .OverlayBitmapAtPath(PATHPOSITION_DISPLAY)

OB.Enable = True

OB.DrawFrameRect RGB(255, 255, 255), 50, 50, 350, 350
OB.DrawLine RGB(255, 255, 255), 50, 200, 350, 200
OB.DrawLine RGB(255, 255, 255), 200, 50, 200, 350
OB.DrawLine RGB(255, 255, 255), 50, 50, 350, 350
OB.DrawLine RGB(255, 255, 255), 50, 350, 350, 50

OB.DrawText RGB(255, 255, 255), 10, 50, "50,50"
OB.DrawText RGB(255, 255, 255), 360, 350, "350,350"
End With

End Sub
Private Sub ICImagingControl1_ImageAvailable(ByVal BufferIndex As Long)
On Error GoTo err_ImageAvailableHandler
Dim x, y, max As Integer
Dim i, j As Long
Static t As Integer ' use for frame counter
Dim DisplayBuffer As ImageBuffer


Set DisplayBuffer = ICImagingControl1.ImageBuffers.Item(BufferIndex)
imagedata = DisplayBuffer.GetImageData

max = imagedata(50, 50)

For y = 50 To 350
For x = 50 To 350
If max < imagedata(x, y) Then
max = imagedata(x, y)
coorx = x + 1
coory = DisplayBuffer.FrameType.Height - y + 1
End If
Next x
Next y

Text1.Text = coorx ' for display of x coordinate of brightest pixel
Text2.Text = coory ' for display of y coordinate of brightest pixel
Text3.Text = max ' for display of value of brightest pixel

For y = 50 To 350
For x = 50 To 350
tempx = tempx + imagedata(x, y) * (x)
tempy = tempy + imagedata(x, y) * (y)
i = i + imagedata(x, y)
Next x
Next y

tempx = tempx / i
tempy = tempy / i

If (t < 10) Then
refcenx = tempx
refceny = tempy
Text4.Text = refceny
Text5.Text = refcenx
Else
cenx = tempx
ceny = tempy
Text6.Text = cenx
Text7.Text = ceny
End If

shiftx = (Abs(cenx - refcenx) * pix_x)
shifty = (Abs(ceny - refceny) * pix_y)

Text8.Text = Round(shiftx, 6)
Text9.Text = Round(shifty, 6)


DisplayBuffer.ReleaseImageData imagedata

ICImagingControl1.DisplayImageBuffer DisplayBuffer
t = t + 1

Exit Sub
err_ImageAvailableHandler:
Debug.Print Err.Description
End Sub
.................................................. .................................................. .......

Stefan Geissler
April 5, 2006, 12:55:00
Hello Dinesh,

Please remove the line
ICImagingControl1.DisplayImageBuffer DisplayBuffer
it is not longer needed.

I could not find any more problems within your code. If you find a problem, that you can not solve, please let me know.