Image detection method, electronic device, and storage medium
An image detection method determines a target object. A plurality of original images of a scene in front of a vehicle are obtained. An object in one original image is detected, and a degree of similarity between the object in the original image and the target object in a preset image is calculated. If the degree of similarity is greater than a preset similarity threshold, it is determined that the original image is a target image and the object is the target object. A position of the target object relative to the vehicle is determined and output. The method can recognize objects of interest in front of a driver.
1 . An image detection method for a vehicle, comprising:
determining a target object;
obtaining a plurality of original images of a scene in front of the vehicle;
detecting a target image comprising the target object from the plurality of original images, comprising: detecting an object in one original image of the plurality of original images, calculating a degree of similarity between the object in the original image and the target object in a preset image, and comprising: adjusting a size of the original image and normalizing the original image by adjusting a center point of the original image and setting the center point to zero (0), extracting features of the object in the original image, and performing preset operations on the features to exclude the features with less information; and calculating a structural similarity index between the features of the object and the target object as the degree of similarity by a structural similarity index algorithm; and determining that the original image is the target image and the object is the target object when the degree of similarity is greater than a preset similarity threshold;
determining a position of the target object relative to the vehicle, comprising obtaining first parameters of an image capturing device that captures the plurality of original images and second parameters of the target object in the target image, the image capturing device comprising two monocular cameras, the first parameters comprising internal parameters of the monocular cameras and a relative position of the monocular cameras, and the second parameters comprising a width of the target object in the target image; performing binocular correction according to the first parameters and the second parameters, matching corresponding pixels in two images captured by the two monocular cameras to obtain a disparity map, calculating disparity data of the two images according to the disparity map; according to the disparity data, calculating a distance of the position by using a similar triangle principle;
outputting the position of the target object relative to the vehicle; and
notifying a driver of the vehicle of the position of the target object relative to the vehicle.
2 . The method of claim 1 , wherein the target object comprises a character string and/or a logo.
3 . The method of claim 1 , wherein obtaining a plurality of original images of a scene in front of the vehicle comprises:
controlling a driving recorder to capture a video of the scene in front of the vehicle;
extracting an image sequence from the video; and
obtaining the plurality of original images from the image sequence.
4 . The method of claim 1 , wherein calculating a degree of similarity between the object in the original image and the target object in a preset image comprises:
extracting features of the object in the original image using a feature extraction algorithm; and
calculating the degree of similarity between the object in the original image and the target object in the preset image according to the features using a feature matching algorithm.
5 . The method of claim 1 , wherein the position of the target object relative to the vehicle comprises a direction of the target object relative to the vehicle, the direction of the target object relative to the vehicle is determined by:
determining a center of the target image, and comparing the target object and the center of the target image to determine the direction of the target object relative to the vehicle; or
determining a road centerline in the target image, and comparing the target object and the road centerline to determine the direction of the target object relative to the vehicle.
6 . The method of claim 1 , wherein outputting the position of the target object relative to the vehicle comprises:
marking the target object and the position of the target object relative to the vehicle in the target image to obtain a marked image, and displaying the marked image; or
issuing a voice message to notify the position of the target object relative to the vehicle.
7 . The method of claim 1 , wherein calculating the distance between the target object and the vehicle according to the first parameters and the second parameters using the monocular vision distance measurement algorithm comprising:
determining a rectangle that encompasses the target object in a target image, and obtaining first coordinates of two pixels on either end of a bottom edge of the rectangle according to the second parameters, the first coordinates being coordinates in an image plane;
determining an external parameter matrix, an internal parameter matrix, and a distortion matrix of the image capturing device according to the first parameters, and obtaining second coordinates of the two pixels according to the first coordinates, the second coordinates being coordinates in a road plane; and
calculating the distance using a Euclidean distance formula according to the second coordinates.
8 . An electronic device installed in a vehicle comprising:
at least one processor; and
a storage device storing computer-readable instructions, which when executed by the at least one processor, cause the at least one processor to:
determine a target object;
obtain a plurality of original images of a scene in front of the vehicle;
detect a target image comprising the target object from the plurality of original images, comprising: detecting an object in one original image of the plurality of original images, calculate a degree of similarity between the object in the original image and the target object in a preset image, and comprising: adjusting a size of the original image and normalizing the original image by adjusting a center point of the original image and setting the center point to zero, extracting features of the object in the original image, and performing preset operations on the features to exclude the features with less information; and calculating a structural similarity index between the features of the object and the target object as the degree of similarity by a structural similarity index algorithm; and determine that the original image is the target image and the object is the target object when the degree of similarity is greater than a preset similarity threshold;
determine a position of the target object relative to the vehicle, comprising obtaining first parameters of an image capturing device that captures the plurality of original images and second parameters of the target object in the target image, the image capturing device comprising two monocular cameras, the first parameters comprising internal parameters of the monocular cameras and a relative position of the monocular cameras, and the second parameters comprising a width of the target object in the target image; perform binocular correction according to the first parameters and the second parameters, match corresponding pixels in two images captured by the two monocular cameras to obtain a disparity map, calculate disparity data of the two images according to the disparity map; according to the disparity data, calculate a distance of the position by using a similar triangle principle;
output the position of the target object relative to the vehicle; and
notify a driver of the vehicle of the position of the target object relative to the vehicle.
9 . The electronic device of claim 8 , wherein the target object comprises a character string and/or a logo.
10 . The electronic device of claim 8 , wherein the at least one processor is further caused to:
control a driving recorder to capture a video of the scene in front of the vehicle;
extract an image sequence from the video; and
obtain the plurality of original images from the image sequence.
11 . The electronic device of claim 8 , wherein the at least one processor is further caused to:
extract features of the object in the original image using a feature extraction algorithm; and
calculate the degree of similarity between the object in the original image and the target object in the preset image according to the features using a feature matching algorithm.
12 . A non-transitory storage medium having stored thereon computer-readable instructions that, when the computer-readable instructions are executed by a processor to implement the following method:
determining a target object;
obtaining a plurality of original images of a scene in front of a vehicle;
detecting a target image comprising the target object from the plurality of original images, comprising: detecting an object in one original image of the plurality of original images, calculating a degree of similarity between the object in the original image and the target object in a preset image, and comprising: adjusting a size of the original image and normalizing the original image by adjusting a center point of the original image and setting the center point to zero, extracting features of the object in the original image, and performing preset operations on the features to exclude the features with less information; and calculating a structural similarity index between the features of the object and the target object as the degree of similarity by a structural similarity index algorithm; and determining that the original image is the target image and the object is the target object when the degree of similarity is greater than a preset similarity threshold;
determining a position of the target object relative to the vehicle, comprising obtaining first parameters of an image capturing device that captures the plurality of original images and second parameters of the target object in the target image, the image capturing device comprising two monocular cameras, the first parameters comprising internal parameters of the monocular cameras and a relative position of the monocular cameras, and the second parameters comprising a width of the target object in the target image; performing binocular correction according to the first parameters and the second parameters, matching corresponding pixels in two images captured by the two monocular cameras to obtain a disparity map, calculating disparity data of the two images according to the disparity map; according to the disparity data, calculating a distance of the position by using a similar triangle principle;
outputting the position of the target object relative to the vehicle; and
notifying a driver of the vehicle of the position of the target object relative to the vehicle.
13 . The non-transitory storage medium of claim 12 , wherein the target object comprises a character string and/or a logo.
14 . The non-transitory storage medium of claim 12 , wherein obtaining a plurality of original images of a scene in front of the vehicle comprises:
controlling a driving recorder to capture a video of the scene in front of the vehicle;
extracting an image sequence from the video; and
obtaining the plurality of original images from the image sequence.
15 . The non-transitory storage medium of claim 12 , wherein calculating a degree of similarity between the object in the original image and the target object in a preset image comprises:
extracting features of the object in the original image using a feature extraction algorithm; and
calculating the degree of similarity between the object in the original image and the target object in the preset image according to the features using a feature matching algorithm.