undistort points instead of image

1,021 views
Skip to first unread message

Ana Rita Fonseca

unread,
May 6, 2015, 8:33:15 AM5/6/15
to bonsai...@googlegroups.com
Does Bonsai allow for undistort node to receive as input a set of coordinates instead of an image?
The idea is to apply the undistort 'transformation' to raw x,y coordinates of center of mass

thanks

arita

goncaloclopes

unread,
May 6, 2015, 9:13:38 AM5/6/15
to bonsai...@googlegroups.com
Unfortunately, it doesn't yet, but it should, so I added it as an issue for the next version:

However, you can have a workaround using a PythonTransform and OpenCV UndistortPoints function. Unfortunately the code gets convoluted, but it does work. Here's an example that takes a single point and outputs the undistorted point. Hopefully you can generalize to what you need but let me know if there are any problems:

import clr
clr
.AddReference("OpenCV.Net")

from System import Array
from OpenCV.Net import CV, Mat, Depth, Point2f

@returns(Point2f)
def process(input):
 
# Initialize input point matrix to 2xN array of points
  points
= Array[float]([input.X, input.Y])
  source
= Mat.FromArray(points,points.Length/2,1,Depth.F64,2)

 
# Create result matrix, will contain undistorted points
  undistorted
= Array.CreateInstance(Point2f,1)
  result
= Mat.CreateMatHeader(undistorted,
                               source
.Rows,
                               source
.Cols,
                               source
.Depth,
                               source
.Channels)

 
# Undistortion parameters
  camera
= Array[float]([1,0,320,0,1,240,0,0,1])
  cameraMatrix
= Mat.FromArray(camera,3,3,Depth.F64,1)
  distortion
= Mat.FromArray(Array[float]([0, 0, 0, 0, 0]))

  CV
.UndistortPoints(source,result,cameraMatrix,distortion)
 
return undistorted[0]


Cheers,
G
Reply all
Reply to author
Forward
0 new messages