vehicleToImage
Convert vehicle coordinates to image coordinates
Description
converts [x
y] or [x
y
z] vehicle coordinates to [x
y] image coordinates by applying a projective transformation.
The monocular camera object, imagePoints
= vehicleToImage(monoCam
,vehiclePoints
)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.
vehiclePoints
— Vehicle points
M-by-2 matrix | M-by-3 matrix
Vehicle points, specified as an M-by-2 or M-by-3 matrix containing M number of [x y] or [x y z] vehicle coordinates.
Output Arguments
imagePoints
— Image points
M-by-2 matrix
Image points, returned as an M-by-2 matrix containing M number of [x y] image coordinates.
More About
Vehicle Coordinate System
In the vehicle coordinate system
(XV,
YV,
ZV) defined by
vehicleToImage
:
The XV-axis points forward from the vehicle.
The YV-axis points to the left, as viewed when facing forward.
The ZV-axis points up from the ground to maintain the right-handed coordinate system.
The default origin of this coordinate system is on the road surface, directly below the camera center. The focal point of the camera defines this center point.
To change the placement of the origin within the vehicle coordinate system, update
the SensorLocation
property.
For more details about the vehicle coordinate system, see Coordinate Systems in Automated Driving Toolbox.
Angle Directions
The monocular camera sensor uses clockwise positive angle directions when looking in the positive direction of the Z-, Y-, and X-axes, respectively.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Version History
Introduced in R2017a
See Also
Objects
Functions
Commande MATLAB
Vous avez cliqué sur un lien qui correspond à cette commande MATLAB :
Pour exécuter la commande, saisissez-la dans la fenêtre de commande de MATLAB. Les navigateurs web ne supportent pas les commandes 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)