Disclosure of Invention
In order to solve the technical problems in the prior art, the technical scheme adopted by the invention is divided into the following two parts:
firstly, a method for determining the positions of chess pieces in a three-dimensional space comprises the following steps: the method comprises the following steps:
step 1, collecting images of chess pieces to be determined in spatial positions, preprocessing the collected images, determining H, S, V ranges of red and green characters on the chess pieces according to different colors of characters on the chess pieces and meanings of components in an HSV color model, and segmenting the red and green chess pieces respectively to obtain two binary images;
step 2, carrying out linear fusion on the two binary images obtained by respectively segmenting the red chess pieces and the green chess pieces, and after the two binary images are fused, mutually covering noise points generated in the extraction process respectively to obtain a pair of binary images which have no noise points and contain the red chess pieces and the green chess pieces;
because the red is brighter, the influence of environmental interference on the red chess pieces during extraction is small, and the method can adapt to most of varied environments; the green is darker, and the main noise when extracting comes from the pixel that has red piece, if the light darkens, then the noise point of red piece position will constantly increase. At this time, when the image extracted from the green chess pieces is preprocessed, the processing process becomes complicated, and the expected effect cannot be achieved. Therefore, the two extracted images are directly fused, so that noise points existing in the green extraction image are covered by the positions of the red chessmen in the red extraction image, the later image preprocessing process is reduced, and the expected extraction effect can be achieved.
Step 3, performing expansion operation on the fused binary image, and connecting adjacent elements in the image to enable the region where each extracted chessman is located to be a single and unrelated connected domain;
step 4, extracting outlines of the chesses in the expanded image, drawing circumscribed circles of the outlines of the chesses, and determining the positions of circle centers through the circumscribed circles, namely the positions of the 32 chesses in the image coordinate system;
step 5, placing the calibration board on the plane where the upper surfaces of the 32 chess pieces are located, and calculating internal and external parameters (H) of the color camera of the Kinect through a calibration function calibretacarama in OpenCVrgb,Rrgb,Trgb) Then, the position of the chess piece under the world coordinate system, namely the position of the chess piece in the space, is further calculated through a conversion relation between an image coordinate system and the world coordinate system in the pinhole-hole model;
step 6, placing the calibration board on the plane where the upper surfaces of the 32 chessmen are located, and calculating internal and external parameters (H) of the depth camera of the Kinect through a calibration function calibretacarama in OpenCVd,Rd,Td);
Because the infrared camera of the Kinect and the depth camera are in the same position, only the infrared camera can be used for acquiring calibration images, and therefore the infrared camera is calibrated, namely the depth camera is calibrated; in the images collected by the infrared camera, the angular points can not be extracted from each image, and the angular point detection is invalid due to the influence of the material of an object, so that more images need to be collected to enable the calibration of the infrared camera to be more accurate, and the number of the collected images is recommended to be 20-25;
step 7, according to world coordinatesPoint of contact (W)p) And a point (K) in the color camera coordinate systemp) The conversion relationship of (1): kp=Rrgb*Wp+TrgbAnd points in the world coordinate system (W)p) And point (K) in the depth camera coordinate systemdp) The conversion relationship of (1): kdp=Rd*Wp+TdCalculating the relation between a Kinect color camera coordinate system and a depth camera coordinate system, and converting a space point under the depth camera coordinate system into a depth pixel coordinate system according to an internal reference calibrated by the depth camera, so that the matching of the space point under the color camera coordinate system and a depth pixel point under the depth image coordinate system is realized; according to the matching method, the positions of the chessmen under the color camera coordinate system are converted into the depth image coordinate system, and the coordinates of the chessmen under the depth coordinate system are calculated;
step 8, extracting depth-of-field information of the coordinates of the chess pieces under the obtained depth pixel coordinate system according to a storage mode of depth-of-field data in the depth image acquired by the Kinect, and obtaining a vertical distance d from the circle center of the upper surface of the chess piece in the space to the plane where the sensor is located;
step 9, projecting the coordinates of the chess pieces obtained in the step 7 in an XOY plane of a depth camera coordinate system according to the coordinates of the chess pieces in the depth camera coordinate system, calculating the distance D1 between a projection point and the origin of the coordinate system, and combining the distance D obtained in the step 8 according to the Pythagorean theorem D2=d12+d2And calculating the actual distance D from the circle center of the upper surface of the chess piece in the space to the sensor, namely, determining the position of the chess piece in the three-dimensional space.
In step 1, gather the image of waiting to confirm position chess piece, carry out image preprocessing to the image of gathering earlier, again according to the difference of characters colour on the chess piece, according to the meaning of each weight in the HSV colour model, confirm the H, S, V scope of red, green characters on the piece, its step includes:
2.1, carrying out spatial correction on the collected chess piece images by adopting a perspective transformation method, and correcting the images into an orthographic projection form;
2.2, setting ROI for the image after perspective transformation;
2.3, determining H, S, V component values of the red and green characters of the chess pieces as follows according to different colors of characters on the chess pieces and the meaning of each component in the HSV color model: the value ranges of red H, S, V are respectively 1-15, 60-255 and 0-93, and the value ranges of green H, S, V are respectively 0-95, 0-255 and 0-93.
Firstly, carrying out spatial correction on an acquired image, and adopting a perspective transformation method to keep a projection geometric figure on a bearing surface unchanged so as to correct the image into an orthographic projection form; secondly, in order to eliminate unnecessary interference of surrounding environment to the chess piece extraction, reduce the time of post image processing and increase the positioning precision of the chess piece coordinates, ROI is set for the image after perspective transformation. Through the perspective transformation and the setting of ROI, the collected source image is processed into the image only with the chessman and the chessboard, and the preparation of the previous stage is made for the next segmentation and space positioning of the chessman.
Because the HSV color model facilitates segmentation of a given color, the chess piece is segmented using the HSV model. According to the difference of the colors of characters on the chess pieces and the significance of each component in the HSV color model, H, S, V ranges of the red characters and the green characters on the chess pieces are determined, and the red characters and the green characters are respectively segmented to obtain two binary images.
In the step 7, the point (W) in the world coordinate system is used as a referencep) And a point (K) in the color camera coordinate systemp) The conversion relationship of (1): kp=Rrgb*Wp+TrgbAnd points in the world coordinate system (W)p) And point (K) in the depth camera coordinate systemdp) The conversion relationship of (1): kdp=Rd*Wp+TdThe method comprises the following steps of calculating the relation between a Kinect color camera coordinate system and a depth camera coordinate system, converting a space point under the depth camera coordinate system into a depth pixel coordinate system according to internal parameters calibrated by a depth camera, and realizing the matching of the space point under the color camera coordinate system and a depth pixel point under a depth image coordinate system, wherein the specific matching method comprises the following steps:
points under the world coordinate System (W)
p) Under the color coordinatePoint (K) of
p) The conversion relationship is as follows: k
p=R
rgb*W
p+T
rgbFirst, a point (W) in the world coordinate system
p) And point (K) in the depth camera coordinate system
dp) The conversion relationship is as follows: k
dp=R
d*W
p+T
dAnd secondly, obtaining the following components by the formula (i):
the formula III is substituted into the formula II to obtain:
point K in the color camera coordinate systempAnd point K in the depth camera coordinate systemdpSatisfies the following conditions: kdp=R*Kp+ T, where R, T is the rotation matrix and translation vector between two coordinates;
combining the formula IV to obtain:
and substituting the formula into the formula to obtain the conversion relation between the point under the color camera coordinate system and the point under the depth camera coordinate system:
then K is putdpAnd multiplying the pixel points by the internal parameters of the depth camera to obtain pixel points under the depth image coordinate system corresponding to the space points under the color camera coordinate system, so that the matching from the space points under the color camera coordinate system to the depth pixel points under the depth image coordinate system is realized.
Secondly, the method for calculating the height of the chess pieces in the three-dimensional space comprises the following steps:
step 1, collecting images of chess pieces to be determined in spatial positions, preprocessing the collected images, determining H, S, V ranges of red and green characters on the chess pieces according to different colors of characters on the chess pieces and meanings of components in an HSV color model, and segmenting the red and green chess pieces respectively to obtain two binary images;
and 2, performing linear fusion on the two binary images obtained by respectively segmenting the red chess pieces and the green chess pieces, and after the two binary images are fused, mutually covering noise points generated in the extraction process to obtain a pair of binary images which have no noise points and contain the red chess pieces and the green chess pieces. Because the noise point is not existed, the speed of the post-image processing is greatly improved, and the steps of the image processing are simplified.
Because the red is brighter, the influence of environmental interference on the red chess pieces during extraction is small, and the method can adapt to most of varied environments; the green is darker, and the main noise when extracting comes from the pixel that has red piece, if the light darkens, then the noise point of red piece position will constantly increase. At this time, when the image extracted from the green chess pieces is preprocessed, the processing process becomes complicated, and the expected effect cannot be achieved. Therefore, the two extracted images are directly fused, so that noise points existing in the green extraction image are covered by the positions of the red chessmen in the red extraction image, the later image preprocessing process is reduced, and the expected extraction effect can be achieved.
Step 3, performing expansion operation on the fused binary image, and connecting adjacent elements in the image to enable the region where each extracted chessman is located to be a single and unrelated connected domain;
step 4, extracting outlines of the chesses in the expanded image, drawing circumscribed circles of the outlines of the chesses, and determining the positions of circle centers through the circumscribed circles, namely the positions of the 32 chesses in the image coordinate system;
step 5, placing the calibration board on the plane where the upper surfaces of the 32 chess pieces are located, and calculating internal and external parameters (H) of the color camera of the Kinect through a calibration function calibretacarama in OpenCVrgb,Rrgb,Trgb) Then passing through a pinhole machine dieThe conversion relation between the image coordinate system and the world coordinate system in the model further calculates the position of the chessman under the world coordinate system, namely the position of the chessman in the space;
step 6, obtaining three-dimensional coordinates of 32 chessmen under the coordinate system of the color camera according to the conversion relation from the world coordinate system to the coordinate system of the color camera, selecting a coordinate point A of one chessman under the coordinate system, and making a vector from the point A to an original point O of the coordinate system of the color camera
Step 7, according to the rotation matrix R of the color camera coordinate system and the world coordinate system
rgbWill vector
Conversion to world coordinate system
Namely, it is
Knowing the world coordinates of the selected point A, and then based on the vector
Uniquely determine the position 1 (X) of the Kinect color camera in the world coordinate system
1,Y
1,Z
1),Z
1Namely the vertical distance from the camera to the plane of the upper surface of the chessman;
step 8, placing the calibration board on the plane of the chessboard surface, collecting the scene image, and carrying out secondary calibration (H) on the color camera
rgb,R
rgb,T
rgb) Then selecting any point B on the calibration plate, converting the point B in the world coordinate system into the camera coordinate system according to the conversion relation between the world coordinate system and the camera coordinate system in the camera pinhole model, and making a vector from the point B to the origin O of the color camera coordinate system
9, according to the rotation matrix R of the color camera coordinate system and the world coordinate system after the secondary calibration
rgbWill vector
Conversion to world coordinate system
Namely, it is
Knowing the world coordinates of the selected point B, and then based on the vector
Uniquely determine the position 2 (X) of the Kinect color camera in the world coordinate system
2,Y
2,Z
2) I.e. the perpendicular distance Z from the camera to the plane of the board surface
2;
Step 10, according to the formula h ═ z2-z1And h is the actual height of the chess pieces.
In step 1, gather the image of waiting to confirm position chess piece, carry out image preprocessing to the image of gathering earlier, again according to the difference of characters colour on the chess piece, according to the meaning of each weight in the HSV colour model, confirm the H, S, V scope of red, green characters on the piece, its step includes:
2.1, carrying out spatial correction on the collected chess piece images by adopting a perspective transformation method, and correcting the images into an orthographic projection form;
2.2, setting ROI for the image after perspective transformation;
2.3, determining H, S, V component values of the red and green characters of the chess pieces as follows according to different colors of characters on the chess pieces and the meaning of each component in the HSV color model: the value ranges of red H, S, V are respectively 1-15, 60-255 and 0-93, and the value ranges of green H, S, V are respectively 0-95, 0-255 and 0-93.
Firstly, carrying out spatial correction on an acquired image, and adopting a perspective transformation method to keep a projection geometric figure on a bearing surface unchanged so as to correct the image into an orthographic projection form; secondly, in order to eliminate unnecessary interference of surrounding environment to the chess piece extraction, reduce the time of post image processing and increase the positioning precision of the chess piece coordinates, ROI is set for the image after perspective transformation. Through the perspective transformation and the setting of ROI, the collected source image is processed into the image only with the chessman and the chessboard, and the preparation of the previous stage is made for the next segmentation and space positioning of the chessman.
Because the HSV color model facilitates segmentation of a given color, the chess piece is segmented using the HSV model. According to the difference of the colors of characters on the chess pieces and the significance of each component in the HSV color model, H, S, V ranges of the red characters and the green characters on the chess pieces are determined, and the red characters and the green characters are respectively segmented to obtain two binary images.
Through the steps 1-10, the reality of the chess pieces is accurately obtained.
The method for determining the positions of the chess pieces in the three-dimensional space can effectively improve the speed of image processing, simplify the flow of image preprocessing by a method for processing noise points, and improve the accuracy of determining the positions of the chess pieces; the method for determining the height of the chess pieces in the three-dimensional space is applicable to height measurement of a single regular object, reduces algorithm complexity and expense of camera purchase, and can be widely applied; the combination of the two methods improves the accuracy of the mechanical hand in grabbing the chessmen.
Detailed Description
The two methods of the present invention are described in further detail below with reference to the figures and examples.
The method for determining the positions of the chess pieces in the three-dimensional space comprises the following steps:
step 1, collecting images of chess pieces to be determined in spatial position, preprocessing the collected images, firstly, carrying out spatial correction on the collected images of the chess pieces by adopting a perspective transformation method, and correcting the images into an orthographic projection form, as shown in fig. 2; secondly, setting ROI for the image after perspective transformation, as shown in FIG. 3; finally, according to the difference of the character colors on the chess pieces and the significance of each component in the HSV color model, the H, S, V component values of the red and green characters of the chess pieces are determined to be as follows through comparison of different illumination conditions and different environments: the value ranges of red H, S, V are respectively 1-15, 60-255 and 0-93, and the value ranges of green H, S, V are respectively 0-95, 0-255 and 0-93. Dividing the red chess pieces and the green chess pieces respectively to obtain two binary images, as shown in figures 4 and 5;
step 2, the two binary images obtained by respectively segmenting the red chess pieces and the green chess pieces are linearly fused, and after the two binary images are fused, noise points generated in the extraction process of the two binary images are mutually covered to obtain a pair of binary images which have no noise points and contain the red chess pieces and the green chess pieces, as shown in fig. 6;
and 3, performing expansion operation on the fused binary image, and connecting adjacent elements in the image to enable the region where each extracted chessman is located to be a single and mutually irrelevant connected domain. In the expansion operation, the kernel with the reference point at the center 10 × 10 is used, as shown in fig. 7;
step 4, extracting outlines of the chess pieces in the expanded image, drawing circumscribed circles of the outlines of the chess pieces, and determining the positions of circle centers through the circumscribed circles, namely the positions of the 32 chess pieces in the image coordinate system, as shown in fig. 8;
step 5, placing the calibration board on the plane where the upper surfaces of the 32 chess pieces are located, and calculating internal and external parameters (H) of the color camera of the Kinect through a calibration function calibretacarama in OpenCVrgb,Rrgb,Trgb) Then go back toThe position of the chess piece under the world coordinate system, namely the position of the chess piece in the space, is further calculated by a conversion relation between an image coordinate system and the world coordinate system in the pinhole camera model;
step 6, placing the calibration board on the plane where the upper surfaces of the 32 chessmen are located, and calculating internal and external parameters (H) of the depth camera of the Kinect through a calibration function calibretacarama in OpenCVd,Rd,Td);
In the images collected by the infrared camera, the angular points can not be extracted from each image, and the angular point detection is invalid due to the influence of the material of an object, so that more images need to be collected to enable the calibration of the infrared camera to be more accurate, and the number of the collected images is 25;
step 7, according to the point (W) in the world coordinate systemp) And a point (K) in the color camera coordinate systemp) The conversion relationship of (1): kp=Rrgb*Wp+TrgbAnd points in the world coordinate system (W)p) And point (K) in the depth camera coordinate systemdp) The conversion relationship of (1): kdp=Rd*Wp+TdCalculating the relation between a Kinect color camera coordinate system and a depth camera coordinate system, and converting a space point under the depth camera coordinate system into a depth pixel coordinate system according to an internal reference calibrated by the depth camera, so that the matching of the space point under the color camera coordinate system and a depth pixel point under the depth image coordinate system is realized; according to the matching method, the positions of the chessmen under the color camera coordinate system are converted into the depth image coordinate system, and the coordinates of the chessmen under the depth coordinate system are calculated;
the matching method of the space point under the color camera coordinate system and the depth pixel point under the depth image coordinate system comprises the following steps:
points under the world coordinate System (W)
p) With point (K) in colour coordinates
p) The conversion relationship is as follows: k
p=R
rgb*W
p+T
rgbFirst, a point (W) in the world coordinate system
p) And point (K) in the depth camera coordinate system
dp) The conversion relationship is as follows: k
dp=R
d*W
p+T
dAnd secondly, obtaining the following components by the formula (i):
the formula III is substituted into the formula II to obtain:
point K in the color camera coordinate systempAnd point K in the depth camera coordinate systemdpSatisfies the following conditions: kdp=R*Kp+ T, where R, T is the rotation matrix and translation vector between two coordinates;
combining the formula IV to obtain:
and substituting the formula into the formula to obtain the conversion relation between the point under the color camera coordinate system and the point under the depth camera coordinate system:
then K is putdpAnd multiplying the pixel points by the internal parameters of the depth camera to obtain pixel points under the depth image coordinate system corresponding to the space points under the color camera coordinate system, so that the matching from the space points under the color camera coordinate system to the depth pixel points under the depth image coordinate system is realized.
Step 8, extracting depth-of-field information of the coordinates of the chess pieces under the obtained depth pixel coordinate system according to a storage mode of depth-of-field data in the depth image acquired by the Kinect, and obtaining a vertical distance d from the circle center of the upper surface of the chess piece in the space to the plane where the sensor is located;
the Kinect depth information is stored in a 16-bit image, the first 13bits are depth, the second 3bits are index values, when no person appears in the image, 16bits can be directly extracted to obtain distance information;
step 9, projecting the coordinates of the chess pieces obtained in the step 7 in an XOY plane of a depth camera coordinate system according to the coordinates of the chess pieces in the depth camera coordinate system, calculating the distance D1 between a projection point and the origin of the coordinate system, and combining the distance D obtained in the step 8 according to the Pythagorean theorem D2=d12+d2And calculating the actual distance D from the circle center of the upper surface of the chess piece in the space to the sensor, namely, determining the position of the chess piece in the three-dimensional space, and obtaining the position of the chess piece in the space and the accurate distance D between the chess piece and the Kinect infrared camera through the steps 1-9, as shown in the following table.
The actual distance from the chess pieces to the sensor is in the image collected by the infrared camera, the angular points of each image can not be extracted, the angular point detection is invalid due to the influence of material of an object, so that more images need to be collected to enable the calibration of the infrared camera to be more accurate, and the number of the collected images is suggested to be 20-25. Secondly, a method for calculating the height of the chessmen comprises the following steps:
step 1, collecting images of chess pieces to be determined in spatial position, preprocessing the collected images, firstly, carrying out spatial correction on the collected images of the chess pieces by adopting a perspective transformation method, and correcting the images into an orthographic projection form, as shown in fig. 2; secondly, setting ROI for the image after perspective transformation, as shown in FIG. 3; finally, according to the difference of the character colors on the chess pieces and the significance of each component in the HSV color model, the H, S, V component values of the red and green characters of the chess pieces are determined to be as follows through experiments on different illumination conditions and different environments: the value ranges of red H, S, V are respectively 1-15, 60-255 and 0-93, and the value ranges of green H, S, V are respectively 0-95, 0-255 and 0-93. Dividing the red chess pieces and the green chess pieces respectively to obtain two binary images, as shown in figures 4 and 5;
step 2, the two binary images obtained by respectively segmenting the red chess pieces and the green chess pieces are linearly fused, and after the two binary images are fused, noise points generated in the extraction process of the two binary images are mutually covered to obtain a pair of binary images which have no noise points and contain the red chess pieces and the green chess pieces, as shown in fig. 6;
and 3, performing expansion operation on the fused binary image, and connecting adjacent elements in the image to enable the region where each extracted chessman is located to be a single and mutually irrelevant connected domain. In the expansion operation, the kernel with the reference point at the center 10 × 10 is used, as shown in fig. 7;
step 4, extracting outlines of the chess pieces in the expanded image, drawing circumscribed circles of the outlines of the chess pieces, and determining the positions of circle centers through the circumscribed circles, namely the positions of the 32 chess pieces in the image coordinate system, as shown in fig. 8;
step 5, placing the calibration board on the plane where the upper surfaces of the 32 chess pieces are located, and calculating internal and external parameters (H) of the color camera of the Kinect through a calibration function calibretacarama in OpenCVrgb,Rrgb,Trgb) Then, the position of the chess piece under the world coordinate system, namely the position of the chess piece in the space, is further calculated through a conversion relation between an image coordinate system and the world coordinate system in the pinhole-hole model;
step 6, obtaining three-dimensional coordinates of 32 chessmen under the coordinate system of the color camera according to the conversion relation from the world coordinate system to the coordinate system of the color camera, selecting a coordinate point A (124, 68, 0) of one chessman under the coordinate system, and making a vector from the point A to an original point O of the coordinate system of the color camera
Step 7, according to the rotation matrix R of the color camera coordinate system and the world coordinate system
rgbWill vector
Conversion to world coordinate system
Namely, it is
Knowing the world coordinates of the selected point A, and then based on the vector
The position 1(-56, 287, 874) of the Kinect color camera under the world coordinate system can be uniquely obtained, namely the vertical distance from the camera to the plane where the upper surface of the chessman is located is 874 mm;
step 8, placing the calibration board on the plane of the chessboard surface, collecting the scene image, and carrying out secondary calibration (H) on the color camera
rgb,R
rgb,T
rgb) Then selecting any point B (0, 0, 0) on the calibration plate, converting the point B in the world coordinate system into the camera coordinate system according to the conversion relation between the world coordinate system and the camera coordinate system in the camera pinhole model, and making a vector from the point B to an origin O of the color camera coordinate system
9, according to the rotation matrix R of the color camera coordinate system and the world coordinate system after the secondary calibration
rgbWill vector
Conversion to world coordinate system
Namely, it is
Knowing the world coordinates of the selected point B, and then based on the vector
The position 2(-87, 209, 886) of the Kinect color camera under the world coordinate system can be uniquely obtained, namely the vertical distance from the camera to the plane where the chessboard surface is located is 886 mm;
step 10, according to the formula h ═ z2-z1H is the actual height of the chess pieces, and the calculated actual height of the chess pieces is 12 mm.