Main Content

monoCamera

Configure monocular camera sensor

Description

ThemonoCameraobject holds information about the configuration of a monocular camera sensor. Configuration information includes the camera intrinsics, camera extrinsics such as its orientation (as described by pitch, yaw, and roll), and the camera location within the vehicle. To estimate the intrinsic and extrinsic camera parameters, seeCalibrate a Monocular Camera.

For images captured by the camera, you can use theimageToVehicleandvehicleToImagefunctions to transform point locations between image coordinates and vehicle coordinates. These functions apply projective transformations (homography), which enable you to estimate distances from a camera mounted on the vehicle to locations on a flat road surface.

Creation

Description

sensor = monoCamera(intrinsics,height)creates amonoCameraobject that contains the configuration of a monocular camera sensor, given the intrinsic parameters of the camera and the height of the camera above the ground.intrinsicsandheightset theIntrinsicsandHeightproperties of the camera.

example

sensor= monoCamera(intrinsics,height,Name,Value)setspropertiesusing one or more name-value pairs. For example,monoCamera(intrinsics,1.5,'Pitch',1)creates a monocular camera sensor that is 1.5 meters above the ground and has a 1-degree pitch toward the ground. Enclose each property name in quotes.

Properties

expand all

Intrinsic camera parameters, specified as either acameraIntrinsicsorcameraParametersobject. The intrinsic camera parameters include the focal length and optical center of the camera, and the size of the image produced by the camera.

You can set this property when you create the object. After you create the object, this property is read-only.

Height from the road surface to the camera sensor, specified as a real scalar. The height is the perpendicular distance from the ground to the focal point of the camera. Specify the height in world units, such as meters. To estimate this value, use theestimateMonoCameraParametersfunction.

Pitch angle between the horizontal plane of the vehicle and the optical axis of the camera, specified as a real scalar in degrees. To estimate this value, use theestimateMonoCameraParametersfunction.

Pitchuses the ISO convention for rotation, with a clockwise positive angle direction when looking in the positive direction of the vehicle'sYVaxis.

Side-by-side images of a camera with the Xv, Yv, and Zv axes labeled. In the first image, the camera is straight. In the second image, the camera is tilted down to indicate a change in pitch angle.

For more details, seeAngle Directions.

Yaw angle between theXVaxis of the vehicle and the optical axis of the camera, specified as a real scalar in degrees. To estimate this value, use theestimateMonoCameraParametersfunction.

Yawuses the ISO convention for rotation, with a clockwise positive angle direction when looking in the positive direction of the vehicle'sZVaxis.

Side-by-side images of a camera with the Xv, Yv, and Zv axes labeled. In the first image, the camera is facing forward. In the second image, the camera is rotated to the left to indicate a change in yaw angle.

For more details, seeAngle Directions.

Roll angle of the camera around its optical axis, returned as a real scalar in degrees. To estimate this value, use theestimateMonoCameraParametersfunction.

Rolluses the ISO convention for rotation, with a clockwise positive angle direction when looking in the positive direction of the vehicle'sXVaxis.

Side-by-side images of a camera with the Xv, Yv, and Zv axes labeled. In the first image, the camera is straight. In the second image, the camera is rotated around its axis to indicate a change in pitch angle.

For more details, seeAngle Directions.

Location of the center of the camera sensor, specified as a two-element vector of the form[xy]. Use this property to change the placement of the camera. Units are in the vehicle coordinate system (XV,YV,ZV).

By default, the camera sensor is located at the (XV,YV) origin, at the height specified byHeight.

Vehicle with front-facing camera and Xv-axis, Yv-axis, and Zv-axis labeled

世界坐标系统单位,指定为一个字符acter vector or string scalar. This property only stores the unit type and does not affect any calculations. Any text is valid.

You can set this property when you create the object. After you create the object, this property is read-only.

Object Functions

imageToVehicle Convert image coordinates to vehicle coordinates
vehicleToImage Convert vehicle coordinates to image coordinates

Examples

collapse all

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 acameraIntrinsicsobject.

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')

Figure contains an axes object. The axes object with title Original Image contains an object of type image.

Determine the image coordinates of a point 10 meters directly in front of the camera. TheX-axis points forward from the camera and theY-axis points to the left.

xyVehicleLoc1 = [10 0]; xyImageLoc1 = vehicleToImage(sensor,xyVehicleLoc1)
xyImageLoc1 =1×2320.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')

Figure contains an axes object. The axes object with title Vehicle-to-Image Point contains an object of type image.

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×26.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')

Figure contains an axes object. The axes object with title Image-to-Vehicle Point contains an object of type image.

Create a vision sensor by using a monocular camera configuration, and generate detections from that sensor.

Specify the intrinsic parameters of the camera and create amonoCameraobject from these parameters. The camera is mounted on top of an ego vehicle at a height of 1.5 meters above the ground and a pitch of 1 degree toward the ground.

focalLength = [800 800]; principalPoint = [320 240]; imageSize = [480 640]; intrinsics = cameraIntrinsics(focalLength,principalPoint,imageSize); height = 1.5; pitch = 1; monoCamConfig = monoCamera(intrinsics,height,'Pitch',pitch);

Create a vision detection generator using the monocular camera configuration.

visionSensor = visionDetectionGenerator (monoCamConfig);

Generate a driving scenario with an ego vehicle and two target cars. Position the first target car 30 meters directly in front of the ego vehicle. Position the second target car 20 meters in front of the ego vehicle but offset to the left by 3 meters.

scenario = drivingScenario; egoVehicle = vehicle(scenario,'ClassID'1);targetCar1 =车辆(scenario,'ClassID',1,'Position',[30 0 0]); targetCar2 = vehicle(scenario,'ClassID',1,'Position',[20 3 0]);

Use a bird's-eye plot to display the vehicle outlines and sensor coverage area.

figure bep = birdsEyePlot('XLim',[0 50],'YLim',[-20 20]); olPlotter = outlinePlotter(bep); [position,yaw,length,width,originOffset,color] = targetOutlines(egoVehicle); plotOutline(olPlotter,position,yaw,length,width); caPlotter = coverageAreaPlotter(bep,'DisplayName','Coverage area','FaceColor','blue'); plotCoverageArea(caPlotter,visionSensor.SensorLocation,visionSensor.MaxRange,...visionSensor.Yaw,visionSensor.FieldOfView(1))

Figure contains an axes object. The axes object contains an object of type patch. This object represents Coverage area.

Obtain the poses of the target cars from the perspective of the ego vehicle. Use these poses to generate detections from the sensor.

poses = targetPoses(egoVehicle); [dets,numValidDets] = visionSensor(poses,scenario.SimulationTime);

Display the (X,Y) positions of the valid detections. For each detection, the (X,Y) positions are the first two values of theMeasurementfield.

fori = 1:numValidDets XY = dets{i}.Measurement(1:2); detXY = sprintf('Detection %d: X = %.2f meters, Y = %.2f meters',i,XY); disp(detXY)end
Detection 1: X = 19.09 meters, Y = 2.79 meters Detection 2: X = 27.81 meters, Y = 0.08 meters

More About

expand all

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Version History

Introduced in R2017a

expand all

Behavior changed in R2018a