A MCU camera positioning method, device, equipment and storage medium
Reading and decompressing USB camera data through the MCU, identifying and correcting positioning marking points, solving the problems of high cost and difficult real-time display of traditional MCU camera positioning methods, and realizing low-cost accurate positioning and real-time display of cameras.
Patent Information
- Application Number
- CN202210501188.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-09
- Publication Date
- 2024-11-22
- Estimated Expiration
- 2042-05-09
AI Technical Summary
Traditional MCU camera positioning methods are expensive in lettering machines and cannot realize real-time image display, mainly due to the speed limitations of external dedicated image processing chips and serial port communication.
The MCU uses the USB interface to read the real-time image data of the USB camera, decompress and perform binarization processing, identify the left and right contours of the positioning mark points, obtain the installation deviation to correct the camera position, and realize the accurate positioning and real-time display of the camera.
It reduces hardware costs, realizes accurate positioning of the camera on the lettering machine and real-time image display, and improves lettering accuracy.
Smart Images

Figure CN114913240B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of engraving machines, and in particular to an MCU camera positioning method, device, equipment and storage medium. Background Art
[0002] In the embedded field, MCU camera positioning is generally achieved through dedicated image processing chips (such as TI DSP6000 series chips) or dedicated large memory and high frequency ARM chips (such as HiSilicon Hi3518). These chips are connected to external cameras through dedicated camera interfaces, and then the collected camera images are processed through dedicated image processing libraries (such as OpenCV, Halcon, etc.) inside the chip to perform positioning. This positioning method requires dedicated image processing chips and ARM chips, and comes with Linux operating systems, etc., with high hardware costs and software real-time costs.
[0003] The main control of the plotter is MCU. Due to speed and resource limitations, the traditional method for the plotter to achieve MCU camera positioning is to connect an external special processing chip to be responsible for image processing and positioning, and then transmit the processing results to the plotter main control MCU through a communication cable. Generally, the camera needs to be installed on the plotter mobile cart, and the main control MCU is generally fixed at the leftmost or rightmost end of the plotter. The communication distance from the cart to the MCU is generally long, so the communication cable is susceptible to interference, and generally only serial communication can be selected. Due to the speed limitation of the serial communication method, the traditional MCU camera positioning solution has a slow image transmission speed and can only transmit positioning results. The main control end cannot display the image in real time; at the same time, due to the need for an external image processing chip, the cost is high. Therefore, how to achieve MCU camera positioning on the plotter system at a low cost while taking into account real-time image display has become a difficult problem that technicians in this field urgently need to solve. Summary of the invention
[0004] The purpose of the present application is to provide an MCU camera positioning method, device, equipment and storage medium. In this scheme, the MCU reads the real-time image data of the USB camera through the USB interface; when it is detected that a complete picture data has been decompressed, the decompressed real-time image data is displayed in real time on the display screen; the decompressed real-time image data is binarized, the left and right contours of the positioning mark point in the real-time image data are identified, and a cutting file is generated; the installation deviation between the camera and the tip of the engraving knife is obtained, and the camera is controlled to move a first distance DeltaX and a second distance DeltaY in the XY direction of the real-time image data respectively according to the installation deviation; the offset compensation is obtained, and the camera is corrected according to the offset compensation and the installation deviation; the camera identifies the positioning mark point on the cutting file according to the left and right contours of the positioning mark point; the coordinate value of the positioning mark point is corrected according to the recognition result of the camera, so as to realize the accurate positioning of the camera on the engraving machine, improve the engraving accuracy, and display the image in real time at a low cost.
[0005] In order to solve the above technical problems, the present application provides an MCU camera positioning method, the method comprising:
[0006] Control MCU to read the real-time image data of USB camera through USB interface;
[0007] Control the MCU to decompress the real-time image data of the USB camera;
[0008] When it is detected that a complete picture data has been decompressed, the decompressed real-time image data is displayed on the display screen in real time;
[0009] Performing binarization processing on the decompressed real-time image data;
[0010] In the real-time image data after binarization, identifying the left and right contours of the positioning mark point in the real-time image data, and generating a cutting file;
[0011] Acquire the installation deviation between the camera and the tip of the engraving knife, and control the camera to move a first distance DeltaX and a second distance DeltaY in the XY direction of the real-time image data respectively according to the installation deviation;
[0012] Obtaining an offset compensation, and calibrating the camera according to the offset compensation and the installation deviation;
[0013] Control the calibrated camera to identify the positioning mark point on the cutting file according to the left and right contours of the positioning mark point;
[0014] The coordinate value of the positioning mark point is corrected according to the recognition result of the camera.
[0015] Preferably, correcting the coordinate value of the positioning mark point according to the recognition result of the camera includes:
[0016] Obtain the initial coordinate position of the preset positioning mark point;
[0017] According to the recognition result of the camera, obtain the actual coordinate position of the positioning mark point;
[0018] Obtain the deviation relationship between the initial coordinate position and the actual coordinate position;
[0019] Correct the coordinate value of the point positioning coordinate point in the cutting file according to the deviation relationship.
[0020] Preferably, the formula for obtaining the offset compensation is:
[0021] offsetX = (cx - IMG_WIDTH / 2) * ratio;
[0022] offseY = (cy - IMG_HEIGHT / 2) * ratio;
[0023] Wherein, offsetX and offseY are the offset compensation values in the XY directions; cx and cy are the center coordinate values of the position where the cutting tool tip is located; IMG_WIDTH is the width value of the real-time image data resolution, and IMG_HEIGHT is the height value of the real-time image data resolution; ratio is the corresponding coefficient of the camera pixel to the actual distance.
[0024] Preferably, in the process of obtaining the offset compensation and correcting the camera according to the offset compensation and the installation deviation, the camera offset value is corrected as:
[0025] DeltaX’ = DeltaX + offsetX;
[0026] DeltaY’ = DeltaY + offsetY.
[0027] Preferably, in the real-time image data after binarization processing, recognizing the left and right contours of the positioning mark point in the real-time image data and generating a cutting file includes:
[0028] Define the left contour array;
[0029] Traverse each row y of the real-time image data from top to bottom, 0 <= y < IMG_WIDTH, where IMG_WIDTH is the width value of the real-time image data resolution;
[0030] Traverse each column x of the real-time image data from left to right, where 0 <= x < IMG_HEIGHT, and perform a judgment on the current point, where IMG_HEIGHT is the high value of the resolution of the real-time image data;
[0031] If the left contour point has not been found in the current row and the previous point is white and the current point is black, then the current point is the left contour;
[0032] Save the x coordinate value of the left contour, and update the previous point to the color value of the current point.
[0033] Preferably, in the real-time image data after binarization processing, identifying the left and right contours of the positioning marker points in the real-time image data and generating a cutting file further includes:
[0034] Define a right contour array;
[0035] Traverse each row y of the real-time image data from top to bottom, where 0 <= y < IMG_WIDTH, where IMG_WIDTH is the width value of the resolution of the real-time image data;
[0036] Traverse each column x of the real-time image data from right to left, where 0 <= x < IMG_HEIGHT, and perform a judgment on the current point, where IMG_HEIGHT is the high value of the resolution of the real-time image data;
[0037] If the right contour point has not been found in the current row and the previous point is white and the current point is black, then the current point is the right contour;
[0038] Save the x coordinate value of the right contour, and update the previous point to the color value of the current point.
[0039] Preferably, when it is detected that the decompression of a complete picture data is completed, the decompressed real-time image data is enlarged and then displayed on the display screen in real time. Enlarging the decompressed real-time image data includes:
[0040] Traverse each row of the real-time image data, where 0 <= y < IMG_HEIGHT, where IMG_HEIGHT is the high value of the resolution of the real-time image data;
[0041] For each row of data, define a temporary array to store the enlarged data;
[0042] Traverse each pixel point of the real-time image data, where 0 <= x < IMG_WIDTH, where IMG_WIDTH is the width value of the resolution of the real-time image data;
[0043] Enlarge the row by a times;
[0044] A row of magnified data is plotted on the display screen.
[0045] In order to solve the above technical problems, the present application provides an MCU camera positioning device, the device comprising:
[0046] The reading module is used to control the MCU to read the real-time image data of the USB camera through the USB interface;
[0047] A decompression module, used to control the MCU to decompress the real-time image data of the USB camera;
[0048] A display control module is used to display the decompressed real-time image data on the display screen in real time when it is detected that a complete picture data is decompressed;
[0049] An image processing module, used for performing binarization processing on the decompressed real-time image data;
[0050] A first recognition module is used to recognize the left and right contours of the positioning mark point in the real-time image data after the binarization process, and generate a cutting file;
[0051] A mobile control module, used for obtaining an installation deviation between the camera and the tip of the engraving knife, and controlling the camera to move a first distance DeltaX and a second distance DeltaY in the XY direction of the real-time image data respectively according to the installation deviation;
[0052] A correction module, used for obtaining offset compensation, and correcting the camera according to the offset compensation and the installation deviation;
[0053] A second recognition module is used to control the calibrated camera to recognize the positioning mark point on the cutting file according to the left and right contours of the positioning mark point;
[0054] A correction module is used to correct the coordinate value of the positioning mark point according to the recognition result of the camera.
[0055] To solve the above technical problems, the present application provides an MCU camera positioning device, comprising: at least one processor, at least one memory, and computer program instructions stored in the memory. When the computer program instructions are executed by the processor, the method of the first aspect in the above embodiment is implemented.
[0056] In order to solve the above technical problems, the present application provides a storage medium on which computer program instructions are stored. When the computer program instructions are executed by a processor, the method of the first aspect in the above embodiment is implemented.
[0057] In summary, an embodiment of the present invention provides an MCU camera positioning method, device, equipment and storage medium. The present invention controls the MCU to read the real-time image data of the USB camera through the USB interface; controls the MCU to decompress the real-time image data of the USB camera; when it is detected that a complete picture data is decompressed, the decompressed real-time image data is displayed in real time on the display screen; the decompressed real-time image data is binarized; in the real-time image data after binarization, the left and right contours of the positioning mark point in the real-time image data are identified to generate a cutting file; the installation deviation between the camera and the tip of the engraving knife is obtained, and the camera is controlled to move the first distance DeltaX and the second distance DeltaY in the XY direction of the real-time image data respectively according to the installation deviation; the offset compensation is obtained, and the camera is corrected according to the offset compensation and the installation deviation; the corrected camera is controlled to identify the positioning mark point on the cutting file according to the left and right contours of the positioning mark point; and the coordinate value of the positioning mark point is corrected according to the recognition result of the camera. Therefore, the present invention realizes the accurate positioning of the camera on the engraving machine, improves the engraving accuracy, and displays the image in real time at a low cost. BRIEF DESCRIPTION OF THE DRAWINGS
[0058] In order to more clearly illustrate the technical solution of the embodiment of the present invention, the following briefly introduces the drawings required for use in the embodiment of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0059] Figure 1 It is a flow chart of an MCU camera positioning method according to an embodiment of the present invention.
[0060] Figure 2 It is a flow chart of an MCU camera positioning method according to an embodiment of the present invention.
[0061] Figure 3 It is a flow chart of an MCU camera positioning method according to an embodiment of the present invention.
[0062] Figure 4 It is a flow chart of an MCU camera positioning method according to an embodiment of the present invention.
[0063] Figure 5 It is a flow chart of an MCU camera positioning method according to an embodiment of the present invention.
[0064] Figure 6 It is a schematic diagram of the outline of positioning mark points of an MCU camera positioning method according to an embodiment of the present invention.
[0065] Figure 7 It is a schematic diagram of a four-point positioning method of an MCU camera positioning method according to an embodiment of the present invention.
[0066] Figure 8 The present invention is a diagram showing the position relationship between a camera and a cutting knife tip in an MCU camera positioning method according to an embodiment of the present invention.
[0067] Fig. 9 It is a structural schematic diagram of an MCU camera positioning device according to an embodiment of the present invention.
[0068] Fig.10 It is a structural schematic diagram of the MCU camera positioning device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0069] The features and exemplary embodiments of various aspects of the present invention will be described in detail below. In order to make the purpose, technical solutions and advantages of the present invention clearer, the present invention will be further described in detail below in conjunction with the accompanying drawings and Examples. It should be understood that the specific embodiments described herein are only configured to explain the present invention and are not configured to limit the present invention. For those skilled in the art, the present invention can be implemented without the need for some of these specific details. The following description of the embodiments is only to provide a better understanding of the present invention by illustrating examples of the present invention.
[0070] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the statement "include..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0071] See also Figure 1 , Figure 1 A flowchart of an MCU camera positioning method provided for this application includes:
[0072] S1, control MCU to read the real-time image data of USB camera through USB interface;
[0073] S2, control MCU to decompress the real-time image data of the USB camera;
[0074] S3, when it is detected that a complete picture data is decompressed, the decompressed real-time image data is displayed on the display screen in real time;
[0075] S4, performing binarization processing on the decompressed real-time image data;
[0076] S5, in the real-time image data after the binarization processing, identifying the left and right contours of the positioning mark point in the real-time image data, and generating a cutting file;
[0077] S6, obtaining the installation deviation between the camera and the tip of the engraving knife, and controlling the camera to move a first distance DeltaX and a second distance DeltaY in the XY direction of the real-time image data respectively according to the installation deviation;
[0078] S7, obtaining offset compensation, and calibrating the camera according to the offset compensation and installation deviation;
[0079] S8, controlling the calibrated camera to identify the positioning mark point on the cutting file according to the left and right contours of the positioning mark point;
[0080] S9. Correct the coordinate value of the positioning mark point according to the recognition result of the camera.
[0081] In the prior art, the engraving machine implements the camera positioning solution by using an external special processing chip to process and position the image, and transmits the processing results to the engraving machine main control MCU through a communication cable. Generally, the camera needs to be installed on the engraving machine's mobile cart, and the main control MCU is fixed at the leftmost or rightmost end of the engraving machine. The communication distance from the engraving machine's mobile cart to the engraving machine's main control MCU is long, and the communication cable is easily interfered with, so generally only the serial communication method can be selected. However, due to the limited speed of the serial communication method, the traditional engraving machine implements the camera positioning solution. The speed of transmitting pictures is slow and the image cannot be displayed in real time; at the same time, due to the need for an external image processing chip, the solution cost is high.
[0082] In view of the above shortcomings, the USB interface in the present application reads the real-time image data of the USB camera; when it is detected that a complete picture data has been decompressed, the decompressed real-time image data is displayed in real time on the display screen; the decompressed real-time image data is binarized, the left and right contours of the positioning mark point in the real-time image data are identified, and a cutting file is generated; the installation deviation between the camera and the tip of the engraving knife is obtained, and the camera is controlled to move the first distance DeltaX and the second distance DeltaY in the XY direction of the real-time image data respectively according to the installation deviation; the offset compensation is obtained, and the camera is corrected according to the offset compensation and the installation deviation; the camera identifies the positioning mark point on the cutting file according to the left and right contours of the positioning mark point; the coordinate value of the positioning mark point is corrected according to the recognition result of the camera, so as to realize the accurate positioning of the camera on the engraving machine, improve the engraving accuracy, and display the image in real time at a low cost.
[0083] Specifically, the purpose of this application is to provide a camera positioning solution in a plotter system with MCU as the main control, which does not require an external dedicated image processing chip, is low-cost, and can take into account real-time image display. The MCU used in this embodiment is STM32F407, with a main frequency of 168M and a memory of 196K, and an external USB camera is connected via USB.
[0084] Specifically, the MCU acts as a USB host and uses the UVC communication protocol to read the image data of the USB camera through the USB interface. It can be understood that the USB cable has strong anti-interference ability and fast transmission speed, which is suitable for real-time transmission of picture streams.
[0085] Specifically, in the uvc communication protocol, the image format is the MPEG compression format, and the image resolution is set to IMG_WIDTH*IMG_HEIGHT. It can be understood that compared with the YUV uncompressed format, the MPEG compression format image processing frame rate is high.
[0086] Specifically, the present application adopts a double buffering method, and two large arrays are opened in the memory to receive pictures. At the beginning, the receiving pointer uvc_ready_framebuffer_ptr points to the first array. After a frame of picture is received, the receiving pointer uvc_ready_framebuffer_ptr immediately switches to the second array. At this time, the MCU takes the picture data of the first array for processing; after the second array receives the picture data, the receiving pointer points to the first array again, and the MCU starts to process the picture data in the second array. Therefore, the data processing speed of the present application is fast, and real-time display of image data can be realized.
[0087] Specifically, when the MCU decompresses the received MPEJ format image data, it needs to reduce memory because it is an embedded scene application decompression. Therefore, this application selects the TJpgDec library for decompression. TJpgDec is a highly optimized decoding module for creating JPEG images in a small embedded system. It occupies low memory when working so that it can be integrated into the MCU chip.
[0088] TJpgDec uses the API function jd_prepare to input the source compressed MJPEG data uvc_ready_framebuffer_ptr, and then compresses the data through the jd_decomp API function. The prototype of the jd_decomp function is:
[0089] JRESULT jd_decomp(
[0090] JDEC*jd,
[0091] UINT(*outfunc)(JDEC*,void*,JRECT*), / *RGB output function* /
[0092] BYTE scale )
[0094] The prototype of the output callback function outfunc is:
[0095] UINT output_func(JDEC*jd,void*bitmap,JRECT*rect)
[0096] bitmap is the decompressed image data, and rect is the length and width information of the image data. The JRECT structure includes left, right, top, and bottom structures, which respectively represent the left edge coordinates, right edge coordinates, top edge coordinates, and bottom edge coordinates of the processed image. Therefore, the rect parameter defines a rectangular block, which corresponds to a rectangular area of the original image. The pixels of this rectangular area are stored in the bitmap array. Since a source image is an image of size IMG_WIDTH*IMG_HEIGHT, it is divided into many blocks for output after decompression by TJpgDec. Therefore, this application creates an array imgData[IMG_WIDTH*IMG_HEIGHT] of size IMG_WIDTH*IMG_HEIGHT to collect the decompressed data. The mapping relationship between the bitmap array and the imgData array is:
[0097] imgData[index2]=bitmap[index1]
[0098] index2=y*IMG_WIDTH+x,
[0099] index1=(right-left+1)*(y-top)+x
[0100] top<=y<=bottom
[0101] left<=x<=right
[0102] Where index2 is the index position of the image mapped to the output image imgData, and index1 is the index position of the image in the small block bitmap. When it is detected that index2 is equal to IMG_WIDTH*IMG_HEIGHT -1, it means that a frame of the image has been decompressed and image processing can begin.
[0103] In summary, the present invention provides an MCU camera positioning method. In this solution, the MCU is controlled to read the real-time image data of the USB camera through the USB interface; the MCU is controlled to decompress the real-time image data of the USB camera; when it is detected that a complete picture data is decompressed, the decompressed real-time image data is displayed in real time on the display screen; the decompressed real-time image data is binarized; in the real-time image data after binarization, the left and right contours of the positioning mark point in the real-time image data are identified to generate a cutting file; the installation deviation between the camera and the tip of the engraving knife is obtained, and the camera is controlled to move the first distance DeltaX and the second distance DeltaY in the XY direction of the real-time image data respectively according to the installation deviation; the offset compensation is obtained, and the camera is corrected according to the offset compensation and the installation deviation; the corrected camera is controlled to identify the positioning mark point on the cutting file according to the left and right contours of the positioning mark point; the coordinate value of the positioning mark point is corrected according to the recognition result of the camera. Therefore, the present invention realizes the accurate positioning of the camera on the engraving machine, improves the engraving accuracy, and displays the image in real time at a low cost.
[0104] Based on the above embodiments:
[0105] Please refer to Figure 2 , Figure 2 This is a flowchart of the MCU camera positioning method provided in this application.
[0106] Please refer to Figure 7 , Figure 7 This is a flowchart of the MCU camera positioning method provided in this application.
[0107] As a preferred embodiment, correcting the coordinate value of the positioning mark point according to the recognition result of the camera includes:
[0108] S91, obtaining the initial coordinate position of the preset positioning mark point;
[0109] S92, obtaining the actual coordinate position of the positioning mark point according to the recognition result of the camera;
[0110] S93, obtaining the deviation relationship between the initial coordinate position and the actual coordinate position;
[0111] S94, correcting the coordinate value of the midpoint positioning coordinate point in the cutting file according to the deviation relationship.
[0112] Specifically, in order to achieve precise positioning and cutting of the engraving machine, the engraving machine will use machine vision positioning technology to print positioning mark points on the cutting medium before officially starting engraving. The camera identifies the coordinate position of the positioning mark points and transmits the coordinate position of the positioning mark points to the engraving machine main control MCU. The engraving machine main control MCU performs the engraving action at the specified position according to the positioning mark points.
[0113] Specifically, the present application prints positioning marks on the cutting medium using a four-point positioning method. After the calibrated camera recognizes the positioning marks on the cutting file based on the left and right contours of the positioning marks, the cutting file will give four marking points on the page to be cut. For example, the marking points are circles, see Figure 7 , in the initial coordinate system XY, the centers of the four circular marking points are A(0,0), B(W,0), C(W,H), and D(0,H). The four marking circles are recognized by the camera, and the center of the first circle is A'(0,0), and the centers of the other three circles are B'(xb',yb'), C'(xc',yc'), and D'(xd',yd'). The new coordinate system where A'B'C'D' is located is X'Y'. Let its rotation angle relative to the initial coordinate system be θ, and the scaling ratios in the XY direction be a and b respectively. For a point (x,y) in the XY coordinate system, its coordinates (x',y') transformed to the X'Y' coordinate system are:
[0114]
[0115] According to B'(xb',yb'), D'(xd',yd'), the equation holds:
[0116]
[0117]
[0118] Then for the point M(xm,ym) defined in the file, its coordinate value M'(xm',ym') in the new coordinate system after camera positioning is:
[0119]
[0120] Therefore, the present application corrects the coordinate value of the positioning mark point according to the recognition result of the camera, so that the coordinate value of the positioning mark point is more accurate, thereby realizing the accurate positioning of the camera on the engraving machine and improving the engraving accuracy.
[0121] Please refer to Figure 8 , Figure 8 A diagram showing the position relationship between the camera and the tip of the engraving knife in the MCU camera positioning method provided in this application.
[0122] As a preferred embodiment, the formula for obtaining the offset compensation is:
[0123] offsetX=(cx-IMG_WIDTH / 2)*ratio;
[0124] offsetY=(cy-IMG_HEIGHT / 2)*ratio;
[0125] Among them, offsetX and offsetY are the offset compensation values in the XY direction; cx and cy are the coordinate values of the center of the circle where the tip of the engraving knife is located; IMG_WIDTH is the width value of the real-time image data resolution, and IMG_HEIGHT is the height value of the real-time image data resolution; ratio is the corresponding coefficient from the camera pixel to the actual distance.
[0126] As a preferred embodiment, in obtaining the offset compensation and calibrating the camera according to the offset compensation and the installation deviation, the camera offset value is corrected as follows:
[0127] DeltaX' = DeltaX + offsetX;
[0128] DeltaY'=DeltaY+offsetY.
[0129] Specifically, since the camera and the engraving knife are both mounted on the mobile cart of the engraving machine, the distance between the camera and the engraving knife is fixed. Figure 8 Before cutting begins, the knife tip is facing the mark point. When taking a photo, due to differences in camera structure, the distance between the camera and the knife on each mobile trolley is different. This error will affect the camera's photo effect, so camera calibration is required to compensate for this installation error. The steps for camera calibration are:
[0130] Replace the tip of the engraving knife with a fine pen tip and draw a small square on the engraving medium. The small square will serve as a marking point.
[0131] According to the preset distance, the camera moves DeltaX and DeltaY distances in the XY direction, moves to the original position of the knife tip, takes pictures, and recognizes the square;
[0132] Based on the identified center positions of the square cx and cy, the offset compensation is calculated to calibrate the camera.
[0133] The offset compensation value is:
[0134] offsetX=(cx-IMG_WIDTH / 2)*ratio;
[0135] offsetY=(cy-IMG_HEIGHT / 2)*ratio;
[0136] Where ratio is the corresponding coefficient from camera pixel to actual distance.
[0137] The camera offset value is corrected to:
[0138] DeltaX' = DeltaX + offsetX;
[0139] DeltaY’ = DeltaY + offsetY.
[0140] Please refer to Figure 3 , Figure 3 , which is the flowchart of the MCU camera positioning method provided by this application.
[0141] As a preferred embodiment, in the real-time image data after binarization processing, identifying the left and right contours of the positioning marker points in the real-time image data, generating a cutting file includes:
[0142] S51. Define a left contour array;
[0143] S52. Traverse each row y of the real-time image data from top to bottom, where 0 <= y < IMG_WIDTH, and IMG_WIDTH is the width value of the real-time image data resolution;
[0144] S53. Traverse each column x of the real-time image data from left to right, where 0 <= x < IMG_HEIGHT, and perform a judgment on the current point, where IMG_HEIGHT is the height value of the real-time image data resolution;
[0145] S54. If the left contour point has not been found in the current row and the previous point is white and the current point is black, then the current point is the left contour;
[0146] S55. Save the x coordinate value of the left contour and update the previous point to the current point color value.
[0147] Please refer to Figure 4 , Figure 4 , which is the flowchart of the MCU camera positioning method provided by this application.
[0148] As a preferred embodiment, in the real-time image data after binarization processing, identifying the left and right contours of the positioning marker points in the real-time image data, generating a cutting file further includes:
[0149] S51'. Define a right contour array;
[0150] S52'. Traverse each row y of the real-time image data from top to bottom, where 0 <= y < IMG_WIDTH, and IMG_WIDTH is the width value of the real-time image data resolution;
[0151] S53'. Traverse each column x of the real-time image data from right to left, where 0 <= x < IMG_HEIGHT, and perform a judgment on the current point, where IMG_HEIGHT is the height value of the real-time image data resolution;
[0152] S54’. If the right contour point has not been found in the current row and the previous point is white while the current point is black, then the current point is the right contour;
[0153] S55’. Save the x - coordinate value of the right contour and update the color value of the previous point to the current point's color value.
[0154] Please refer to Figure 6 , Figure 6 which is the contour schematic diagram of the positioning marker points of the MCU camera positioning method provided by this application.
[0155] Specifically, the marker points used for engraving machine positioning mainly include hollow squares and solid circles. The images recognized by this application are solid circles and hollow squares, as Figure 6 shown. First, define the left and right contour arrays ColorArrLeft[IMG_HEIGHT] and ColorArrRight[IMG_HEIGHT], and set the initial values of all array elements to 0, indicating that the contour points have not been found yet.
[0156] The method for identifying the left contour is as follows:
[0157] Traverse each row y of the image from top to bottom, where 0 <= y < IMG_WIDTH;
[0158] Traverse each column x of the image from left to right, where 0 <= x < IMG_HEIGHT, and perform the following judgment on the current point:
[0159] If the left contour point has not been found in the current row (ColorArrLeft[y] == 0) and the previous point is white while the current point is black, then the current point is the left contour. Save the current left contour abscissa value ColorArrLeft[y] = x, and update the color value of the previous point to the current point's color value.
[0160] The method for identifying the right contour is as follows:
[0161] Traverse each row y of the image from top to bottom, where 0 <= y < IMG_WIDTH;
[0162] Traverse each column x of the image from right to left, where 0 <= x < IMG_HEIGHT, and perform the following judgment on the current point:
[0163] If the right contour point has not been found in the current row (ColorArrRight[y] == 0) and the previous point is white while the current point is black, then the current point is the right contour. Save the current right contour abscissa value ColorArrRight[y] = x, and update the color value of the previous point to the current point's color value.
[0164] Specifically, when identifying a square, since the position of the square can ensure that its two vertical sides are basically parallel to the y-axis, it is necessary to traverse all the left contour points to find the coordinate value with the highest occurrence probability of the abscissa, which is the coordinate of the left edge of the square; similarly, traverse all the right contour points to find the coordinate value with the highest occurrence probability of the abscissa, which is the coordinate of the right edge of the square.
[0165] Specifically, the algorithm steps for identifying a square are as follows:
[0166] Create arrays timesLeft[IMG_WIDTH] and timesRight[IMG_WIDTH], and initialize all elements to 0;
[0167] Traverse all values from 0 to IMG_HEIGHT, where 0 <= i < IMG_HEIGHT, and perform the following operations:
[0168] If ColorArrLeft[i]!= 0, then timesLeft[ColorArrLeft[i]]++;
[0169] If ColorArrRight[i]!= 0, then timesRight[ColorArrRight[i]]++;
[0170] Find the maximum value in the ColorArrLeft array, and its corresponding index is the abscissa value meanLeft of the left edge of the square; find the maximum value in the ColorArrRight array, and its corresponding index is the abscissa value meanRight of the right edge of the square. Calculate the width of the square width = meanRight - meanLeft. Count the number of points inlineLeft with abscissa values near meanLeft in the left contour, count the number of points inlineRight with abscissa values near meanRight in the right contour points, count the number of left contour points countsLeft, and count the number of right contour points countsRight. Count the maximum value max_y of the ordinate and the minimum value min_y of the ordinate in the left contour, and calculate the height of the square height = max - min_y. When inlineLeft / countsLeft > 80% and inlineRight / countsRight > 80% and abs(width - height) < error value 5, it is considered that the square is found, and calculate the center coordinates of the square cx = (meanLeft + meanRight) / 2, cy = (max_y + min_y) / 2.
[0171] Specifically, the algorithm steps for identifying a circle are as follows:
[0172] For the left contour, a distance-based filtering method is used to remove outliers. There are some outliers around the circle. The method to filter out outliers is: traverse all points in the left contour, and for each point, calculate the distance between the point and other points in the contour. If the distance is less than the distance threshold, the neighboring point counter nearCount++, if the last nearCount<point count threshold, then the point is considered an outlier and removed from the left contour point set.
[0173] For the left contour point set, perform the least squares fitting to fit the center coordinates (cx, cy) and radius r
[0174] For N point sets (x1, y1), (x2, y2), ..., (xn, yn), the formula for finding the center and radius by the least squares method is:
[0175]
[0176]
[0177]
[0178]
[0179]
[0180]
[0181]
[0182]
[0183]
[0184] Traverse all points on the contour and calculate their distance d from the center of the fitted circle (cx, cy). If the absolute value of the distance d and r is less than the threshold value, the point is considered to be on the contour, and the number of points on the contour cirCnt is increased by 1. And count the number of all contour points count. After traversal, calculate the percentage cirCnt / count. If cirCnt / count>80%, the circle is considered to be successfully identified.
[0185] Please refer to Figure 5 , Figure 5 This is a flowchart of the MCU camera positioning method provided in this application.
[0186] As a preferred embodiment, when it is detected that a complete picture data is decompressed, the decompressed real-time image data is enlarged and then displayed in real time on the display screen. Enlarging the decompressed real-time image data includes:
[0187] S31. Traverse each row of the real-time image data, where \(0\leq y < \text{IMG_HEIGHT}\), and \(\text{IMG_HEIGHT}\) is the high value of the resolution of the real-time image data;
[0188] S32. For each row of data, define a temporary array to store the magnified data;
[0189] S33. Traverse each pixel point of the real-time image data, where \(0\leq x < \text{IMG_WIDTH}\), and \(\text{IMG_WIDTH}\) is the width value of the resolution of the real-time image data;
[0190] S34. Magnify the row by a factor of \(a\);
[0191] S35. Draw the magnified data of \(a\) rows on the display screen.
[0192] Specifically, when it is detected that the decompression of a complete picture data is completed, this picture is displayed on the LCD screen. Since the area of \(\text{IMG_WIDTH}*\text{IMG_HEIGHT}\) is relatively small when displayed on the screen, in this application, the length and width of the picture are magnified by 2 times before being displayed on the screen. The method of magnifying the picture is as follows: Traverse each row of the image, where \(0\leq y < \text{IMG_HEIGHT}\); for each row of data, define a temporary array \(\text{color}[\text{IMG_WIDTH}*2]\) to store the magnified data, and then traverse each pixel point where \(0\leq x < \text{IMG_WIDTH}\); magnify the row by 2 times;
[0193] index = \(\text{IMG_WIDTH}*y + x\)
[0194] \(\text{color}[2*x]=\text{imgData}[index]\)
[0195] \(\text{color}[2*x + 1]=\text{imgData}[index]\)
[0196] \(\text{color}[2*x + 2*\text{IMG_WIDTH}]=\text{imgData}[index]\)
[0197] \(\text{color}[2*x + 2*\text{IMG_WIDTH}]=\text{imgData}[index]\); Draw the magnified data of 2 rows on the screen; Draw the pixel points of these 2 rows of \(2*y, 2*y + 1\) to the screen according to the \(\text{color}\) array.
[0198] Specifically, for image processing of the image, first convert the image to a grayscale image. Since the color format of the image after MPEG decompression is RGB565 format, for each 16-bit pixel point \(\text{color}\), first extract the R, G, B components, and then perform grayscale conversion. The grayscale value Gray is:
[0199] R=color>>11
[0200] B=color&0x1F
[0201] G=(color>>5)&0x3F
[0202] Gray=R*0.299+0.578*G+0.114*B.
[0203] See also Fig. 9 , Fig. 9 This is a structural diagram of an MCU camera positioning device for this application.
[0204] The present application also provides an MCU camera positioning device, the device comprising:
[0205] Reading module 1, used to control MCU to read real-time image data of USB camera through USB interface;
[0206] Decompression module 2, used to control MCU to decompress the real-time image data of the USB camera;
[0207] Display control module 3, used for displaying the decompressed real-time image data on the display screen in real time when it is detected that a complete picture data is decompressed;
[0208] The image processing module 4 is used to perform binarization processing on the decompressed real-time image data;
[0209] The first recognition module 5 is used to recognize the left and right contours of the positioning mark point in the real-time image data after the binarization process, and generate a cutting file;
[0210] A mobile control module 6 is used to obtain the installation deviation between the camera and the tip of the engraving knife, and control the camera to move a first distance DeltaX and a second distance DeltaY in the XY direction of the real-time image data according to the installation deviation;
[0211] A correction module 7, used to obtain offset compensation and calibrate the camera according to the offset compensation and installation deviation;
[0212] The second recognition module 8 is used to control the calibrated camera to recognize the positioning mark point on the cutting file according to the left and right contours of the positioning mark point;
[0213] The correction module 9 is used to correct the coordinate value of the positioning mark point according to the recognition result of the camera.
[0214] In addition, combined Figure 1 The MCU camera positioning method described in the embodiment of the present invention can be implemented by an MCU camera positioning device. Fig.10A schematic diagram of the hardware structure of an MCU camera positioning device provided in an embodiment of the present invention is shown.
[0215] The MCU camera positioning device may include a processor 401 and a memory 402 storing computer program instructions.
[0216] Specifically, the processor 401 may include a central processing unit (CPU), or an application specific integrated circuit (ASIC), or may be configured to implement one or more integrated circuits of the embodiment of the present invention.
[0217] Memory 402 may include a large capacity memory for data or instructions. For example, but not limitation, memory 402 may include a hard disk drive (HDD), a floppy disk drive, a flash memory, an optical disk, a magneto-optical disk, a magnetic tape, or a universal serial bus (USB) drive or a combination of two or more of these. In appropriate cases, memory 402 may include a removable or non-removable (or fixed) medium. In appropriate cases, memory 402 may be inside or outside a data processing device. In a specific embodiment, memory 402 is a non-volatile solid-state memory. In a specific embodiment, memory 402 includes a read-only memory (ROM). In appropriate cases, the ROM may be a mask-programmed ROM, a programmable ROM (PROM), an erasable PROM (EPROM), an electrically erasable PROM (EEPROM), an electrically rewritable ROM (EAROM) or a flash memory or a combination of two or more of these.
[0218] The processor 401 implements any one of the MCU camera positioning methods in the above embodiments by reading and executing computer program instructions stored in the memory 402.
[0219] In one example, the MCU camera positioning device may further include a communication interface 403 and a bus 410. Fig.10 As shown, the processor 401, the memory 402, and the communication interface 403 are connected via a bus 410 and communicate with each other.
[0220] The communication interface 403 is mainly used to implement the communication between the modules, devices, units and / or equipment in the embodiment of the present invention.
[0221] Bus 410 includes hardware, software or both, coupling the components of the MCU camera positioning device to each other. By way of example and not limitation, the bus may include an accelerated graphics port (AGP) or other graphics bus, an enhanced industrial standard architecture (EISA) bus, a front-side bus (FSB), a hypertransport (HT) interconnect, an industrial standard architecture (ISA) bus, an infinite bandwidth interconnect, a low pin count (LPC) bus, a memory bus, a microchannel architecture (MCA) bus, a peripheral component interconnect (PCI) bus, a PCI-Express (PCI-X) bus, a serial advanced technology attachment (SATA) bus, a video electronics standard association local (VLB) bus or other suitable bus or a combination of two or more of these. Where appropriate, bus 410 may include one or more buses. Although embodiments of the present invention describe and illustrate specific buses, the present invention contemplates any suitable bus or interconnect.
[0222] In addition, in combination with an MCU camera positioning method in the above embodiment, an embodiment of the present invention can provide a computer-readable storage medium for implementation. The computer-readable storage medium stores computer program instructions; when the computer program instructions are executed by a processor, any MCU camera positioning method in the above embodiment is implemented.
[0223] It should also be noted that the exemplary embodiments mentioned in the present invention describe some methods or systems based on a series of steps or devices. However, the present invention is not limited to the order of the above steps, that is, the steps can be performed in the order mentioned in the embodiments, or in a different order from the embodiments, or several steps can be performed simultaneously.
[0224] The above is only a specific implementation of the present invention. Those skilled in the art can clearly understand that for the convenience and simplicity of description, the specific working processes of the systems, modules and units described above can refer to the corresponding processes in the aforementioned method embodiments, and will not be repeated here. It should be understood that the protection scope of the present invention is not limited to this. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed by the present invention, and these modifications or replacements should be covered within the protection scope of the present invention.
Claims
1. A MCU camera positioning method, It is characterized in that The method comprises: Control MCU to read the real-time image data of USB camera through USB interface; Control the MCU to decompress the real-time image data of the USB camera; When it is detected that a complete picture data has been decompressed, the decompressed real-time image data is displayed on the display screen in real time; Performing binarization processing on the decompressed real-time image data; In the real-time image data after binarization, identifying the left and right contours of the positioning mark point in the real-time image data, and generating a cutting file; Acquire the installation deviation between the camera and the tip of the engraving knife, and control the camera to move a first distance DeltaX and a second distance DeltaY in the XY direction of the real-time image data respectively according to the installation deviation; Obtaining an offset compensation, and calibrating the camera according to the offset compensation and the installation deviation; Control the calibrated camera to identify the positioning mark point on the cutting file according to the left and right contours of the positioning mark point; The coordinate value of the positioning mark point is corrected according to the recognition result of the camera.
2. A MCU camera positioning method according to claim 1, It is characterized in that The step of correcting the coordinate value of the positioning mark point according to the recognition result of the camera includes: Obtaining the preset initial coordinate position of the positioning mark point; According to the recognition result of the camera, the actual coordinate position of the positioning mark point is obtained; Obtaining a deviation relationship between the initial coordinate position and the actual coordinate position; The coordinate value of the midpoint positioning coordinate point in the cutting file is corrected according to the deviation relationship.
3. A MCU camera positioning method according to claim 1, It is characterized in that The formula for obtaining the offset compensation is: offsetX=(cx-IMG_WIDTH / 2)*ratio; offsetY=(cy-IMG_HEIGHT / 2)*ratio; Among them, offsetX and offsetY are the offset compensation values in the XY direction; cx and cy are the center coordinate values of the position of the cutting knife tip; IMG_WIDTH is the width value of the real-time image data resolution, and IMG_HEIGHT is the height value of the real-time image data resolution; ratio is the corresponding coefficient from the camera pixel to the actual distance.
4. The MCU camera positioning method according to claim 2, It is characterized in that In the obtaining of the offset compensation and the correction of the camera according to the offset compensation and the installation deviation, the camera offset value correction is: DeltaX' = DeltaX + offsetX; DeltaY'=DeltaY+offsetY.
5. The MCU camera positioning method according to claim 1, It is characterized in that The step of identifying the left and right contours of the positioning mark points in the real-time image data after the binarization process and generating a cutting file comprises: Define the left contour array; Traverse each row y of the real-time image data from top to bottom, where 0 <= y < IMG_WIDTH, and IMG_WIDTH is the width value of the resolution of the real-time image data; Traverse each column x of the real-time image data from left to right, where 0 <= x < IMG_HEIGHT, and perform a judgment on the current point, where IMG_HEIGHT is the height value of the resolution of the real-time image data; If the left contour point has not been found in the current row and the previous point is white and the current point is black, then the current point is the left contour; Save the x coordinate value of the left contour, and update the previous point to the color value of the current point.
6. A method for positioning an MCU camera according to claim 5, characterized in that, In the real-time image data after binarization processing, identifying the left and right contours of the positioning marker points in the real-time image data and generating a cutting file further includes: Define a right contour array; Traverse each row y of the real-time image data from top to bottom, where 0 <= y < IMG_WIDTH, and IMG_WIDTH is the width value of the resolution of the real-time image data; Traverse each column x of the real-time image data from right to left, where 0 <= x < IMG_HEIGHT, and perform a judgment on the current point, where IMG_HEIGHT is the height value of the resolution of the real-time image data; If the right contour point has not been found in the current row and the previous point is white and the current point is black, then the current point is the right contour; Save the x coordinate value of the right contour, and update the previous point to the color value of the current point.
7. A method for positioning an MCU camera according to claim 1, characterized in that, When it is detected that the decompression of a complete picture data is completed, magnify the decompressed real-time image data and then display it on the display screen in real time. Magnifying the decompressed real-time image data includes: Traverse each row of the real-time image data, where 0 <= y < IMG_HEIGHT, and IMG_HEIGHT is the height value of the resolution of the real-time image data; For each row of data, define a temporary array to store the magnified data; Traverse each pixel point of the real-time image data, where 0 <= x < IMG_WIDTH, and IMG_WIDTH is the width value of the resolution of the real-time image data; Magnify the row by a times; Draw the magnified data of a rows on the display screen.
8. An MCU camera positioning device, characterized in that, The device includes: A reading module for controlling the MCU to read the real-time image data of the USB camera through the USB interface; A decompression module for controlling the MCU to decompress the real-time image data of the USB camera; A display control module for, when it is detected that the decompression of a complete picture data is completed, displaying the decompressed real-time image data on the display screen in real time; An image processing module for performing binarization processing on the decompressed real-time image data; A first recognition module for identifying the left and right contours of the positioning marker points in the real-time image data after binarization processing and generating a cutting file; A mobile control module, used for obtaining an installation deviation between the camera and the tip of the engraving knife, and controlling the camera to move a first distance DeltaX and a second distance DeltaY in the XY direction of the real-time image data respectively according to the installation deviation; A correction module, used for obtaining offset compensation, and correcting the camera according to the offset compensation and the installation deviation; A second recognition module is used to control the calibrated camera to recognize the positioning mark point on the cutting file according to the left and right contours of the positioning mark point; A correction module is used to correct the coordinate value of the positioning mark point according to the recognition result of the camera.
9. An MCU camera positioning device, It is characterized in that include: At least one processor, at least one memory and computer program instructions stored in the memory, when the computer program instructions are executed by the processor, implement the method according to any one of claims 1 to 7.
10. A storage medium having computer program instructions stored thereon, It is characterized in that When the computer program instructions are executed by a processor, the method according to any one of claims 1 to 7 is implemented.
