imageToVehicle
Convert image coordinates to vehicle coordinates
Description
converts image coordinates to [x
y] vehicle coordinates by applying a projective
transformation. The monocular camera object, vehiclePoints
= imageToVehicle(monoCam
,imagePoints
)monoCam
,
contains the camera parameters.
Examples
Create Monocular Camera Object
Create a forward-facing monocular camera sensor mounted on an ego vehicle. Examine an image captured from the camera and determine locations within the image in both vehicle and image coordinates.
Set the intrinsic parameters of the camera. Specify the focal length, the principal point of the image plane, and the output image size. Units are in pixels. Save the intrinsics as a cameraIntrinsics
object.
focalLength = [800 800]; principalPoint = [320 240]; imageSize = [480 640]; intrinsics = cameraIntrinsics(focalLength,principalPoint,imageSize);
Specify the position of the camera. Position the camera 2.18 meters above the ground with a 14-degree pitch toward the ground.
height = 2.18; pitch = 14;
Define a monocular camera sensor using the intrinsic camera parameters and the position of the camera. Load an image from the camera.
sensor = monoCamera(intrinsics,height,'Pitch',pitch); Ioriginal = imread('road.png'); figure imshow(Ioriginal) title('Original Image')
Determine the image coordinates of a point 10 meters directly in front of the camera. The X-axis points forward from the camera and the Y-axis points to the left.
xyVehicleLoc1 = [10 0]; xyImageLoc1 = vehicleToImage(sensor,xyVehicleLoc1)
xyImageLoc1 = 1×2
320.0000 216.2296
Display the point on the image.
IvehicleToImage = insertMarker(Ioriginal,xyImageLoc1); IvehicleToImage = insertText(IvehicleToImage,xyImageLoc1 + 5,'10 meters'); figure imshow(IvehicleToImage) title('Vehicle-to-Image Point')
Determine the vehicle coordinates of a point that lies on the road surface in the image.
xyImageLoc2 = [300 300]; xyVehicleLoc2 = imageToVehicle(sensor,xyImageLoc2)
xyVehicleLoc2 = 1×2
6.5959 0.1732
The point is about 6.6 meters in front of the vehicle and about 0.17 meters to the left of the vehicle center.
Display the vehicle coordinates of the point on the image.
IimageToVehicle = insertMarker(Ioriginal,xyImageLoc2); displayText = sprintf('(%.2f m, %.2f m)',xyVehicleLoc2); IimageToVehicle = insertText(IimageToVehicle,xyImageLoc2 + 5,displayText); figure imshow(IimageToVehicle) title('Image-to-Vehicle Point')
Input Arguments
monoCam
— Monocular camera parameters
monoCamera
object
Monocular camera parameters, specified as a monoCamera
object.
imagePoints
— Image points
M-by-2 matrix
Image points, specified as an M-by-2 matrix containing M number of [x y] image coordinates.
Output Arguments
vehiclePoints
— Vehicle points
M-by-2 matrix
Vehicle points, returned as an M-by-2 matrix containing M number of [x y] vehicle coordinates.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Version History
Introduced in R2017a
See Also
Objects
Functions
MATLAB 명령
다음 MATLAB 명령에 해당하는 링크를 클릭했습니다.
명령을 실행하려면 MATLAB 명령 창에 입력하십시오. 웹 브라우저는 MATLAB 명령을 지원하지 않습니다.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)