Ask Your Question

BIM's profile - activity

2012-07-21 11:18:47 -0600 received badge  Editor (source)
2012-07-21 08:21:24 -0600 asked a question Undistort Border calculation

Hallo, Hallo

I have have a good Image when I use the undistort- function on the Image. My problem is, that I lose to many Image-information (area). I think the problem is, that the new undistort-image has the same size as the original. My idea was to enlarge the original image and to see the full image content. The problem is calculating the needed border. Here is my Code:

Dim P(1) As PointF ‘Corner from the Image
Dim fx As Double = myIntrinsicParam.IntrinsicMatrix(0, 0)
Dim fy As Double = myIntrinsicParam.IntrinsicMatrix(1, 1)
Dim cx As Double = myIntrinsicParam.IntrinsicMatrix(0, 2) ‘Refpoint in X
Dim cy As Double = myIntrinsicParam.IntrinsicMatrix(1, 2) ‘Refpoint in Y

P(0).X = 0
P(0).Y = 0
P(1).X = ImageSize.Width
P(1).Y = ImageSize.Height

P = myIntrinsicParam.Undistort(P, Nothing, Nothing)
Dim i As Integer
‘multiplication to camera matrix px = px * fx + cx; py = py * fy + cy; } 

For i = 0 To P.Length – 1
P(i).X = CSng(P(i).X * fx + cx)
P(i).Y = CSng(P(i).Y * fy + cy)
Next
UndistortBorder = New Rectangle(CInt(-P(0).X), CInt(-P(0).Y), CInt(P(1).X – P(0).X), CInt(P(1).Y – P(0).Y))

I wanted to calculate the new image size and offset.

Dim BorderColor As MCvScalar = New MCvScalar(0, 0, 0) ‘Black
Dim ImageLarge As Image(Of Gray, Byte)
ImageLarge = New Image(Of Gray, Byte)(UndistortBorder.Width, UndistortBorder.Height)

CvInvoke.cvCopyMakeBorder(image.Ptr, ImageLarge.Ptr, UndistortBorder.Location, CvEnum.BORDER_TYPE.CONSTANT, BorderColor)

With this solution is my calculated offset too big. What is my fault ?

Mike