CN114913240B - A MCU camera positioning method, device, equipment and storage medium - Google Patents
A MCU camera positioning method, device, equipment and storage medium Download PDFInfo
- Publication number
- CN114913240B CN114913240B CN202210501188.2A CN202210501188A CN114913240B CN 114913240 B CN114913240 B CN 114913240B CN 202210501188 A CN202210501188 A CN 202210501188A CN 114913240 B CN114913240 B CN 114913240B
- Authority
- CN
- China
- Prior art keywords
- real
- camera
- image data
- time image
- mcu
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T7/00—Image analysis
- G06T7/80—Analysis of captured images to determine intrinsic or extrinsic camera parameters, i.e. camera calibration
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T1/00—General purpose image data processing
- G06T1/0014—Image feed-back for automatic industrial control, e.g. robot with camera
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T7/00—Image analysis
- G06T7/10—Segmentation; Edge detection
- G06T7/136—Segmentation; Edge detection involving thresholding
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T7/00—Image analysis
- G06T7/70—Determining position or orientation of objects or cameras
- G06T7/73—Determining position or orientation of objects or cameras using feature-based methods
- G06T7/74—Determining position or orientation of objects or cameras using feature-based methods involving reference images or patches
Landscapes
- Engineering & Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Theoretical Computer Science (AREA)
- Computer Vision & Pattern Recognition (AREA)
- Robotics (AREA)
- Image Analysis (AREA)
- Length Measuring Devices By Optical Means (AREA)
Abstract
The invention discloses a method, a device, equipment and a storage medium for positioning an MCU camera. The invention reads the real-time image data of the USB camera through the USB interface by controlling the MCU; controlling the MCU to decompress real-time image data of the USB camera; displaying the decompressed real-time image data in real time to a display screen; binarizing the decompressed real-time image data; identifying left and right outlines of positioning mark points in the real-time image data; controlling the camera to respectively 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; obtaining offset compensation, and correcting the camera according to the offset compensation and the installation deviation; the corrected camera is controlled to identify the positioning mark points on the cutting file according to the left and right outlines of the positioning mark points; and correcting the coordinate value of the positioning mark point according to the identification result of the camera. The invention realizes the accurate positioning of the camera on the engraving machine and improves the engraving precision; the image can be displayed in real time, and the cost is low.
Description
Technical Field
The invention relates to the technical field of lettering machines, in particular to a method, a device, equipment and a storage medium for positioning an MCU camera.
Background
In the embedded field, the positioning of the MCU camera is generally performed through a special image processing chip (such as a TI DSP6000 series chip) or a special large-memory high-main-frequency ARM chip (such as Haishu Hi 3518), the chips are externally connected with the camera through a special camera interface, and then the collected camera pictures are processed through a special image processing library (such as OpenCV, halcon and the like) in the chip, so that the positioning is performed. The positioning method needs a special image processing chip and an ARM chip, and is accompanied by a Linux operating system and the like, so that the hardware cost and the software real-time cost are high.
The main control of the carving machine is MCU, and the traditional method for realizing the positioning of the MCU camera by the carving machine is to connect with a special processing chip for image processing and positioning, and then transmit the processing result to the main control MCU of the carving machine through a communication cable. The general camera needs to be arranged on the mobile trolley of the carving machine, the main control MCU is generally fixed at the leftmost or rightmost end of the carving machine, and the communication distance from the trolley to the MCU is generally longer, so that the communication cable is easy to be interfered, and only a serial port communication mode can be generally selected. Because the speed of the serial port communication mode is limited, the traditional MCU camera positioning scheme has low picture transmission speed, only can transmit positioning results, and the main control end cannot display images in real time; meanwhile, the cost is high because of the need of externally connecting an image processing chip. Therefore, how to realize the positioning of the MCU camera on the lettering machine system with low cost and simultaneously display the images in real time becomes a difficult problem to be solved by those skilled in the art.
Disclosure of Invention
The application aims to provide a method, a device, equipment and a storage medium for positioning an MCU camera, wherein in the scheme, the MCU reads real-time image data of the USB camera through a USB interface; when the decompression of the complete picture data is detected, displaying the decompressed real-time image data in a display screen in real time; binarizing the decompressed real-time image data, and identifying left and right outlines of positioning mark points in the real-time image data to generate a cutting file; acquiring the installation deviation of the camera and the tip of the nicking tool, and controlling the camera to move a first distance DeltaX and a second distance DeltaY respectively in the XY direction of real-time image data according to the installation deviation; obtaining offset compensation, and correcting the camera according to the offset compensation and the installation deviation; the camera identifies the positioning mark points on the cutting file according to the left and right outlines of the positioning mark points; and the coordinate value of the positioning mark point is corrected according to the identification result of the camera, so that the accurate positioning of the camera on the carving machine is realized, the carving precision is improved, the image is displayed in real time, and the cost is low.
In order to solve the technical problems, the application provides a positioning method of an MCU camera, which comprises the following steps:
the control MCU reads real-time image data of the USB camera through the USB interface;
controlling the MCU to decompress real-time image data of the USB camera;
When the decompression of the complete picture data is detected, displaying the decompressed real-time image data in a display screen in real time;
Performing binarization processing on the decompressed real-time image data;
identifying left and right contours of positioning mark points in the real-time image data after binarization processing to generate a cutting file;
Acquiring the installation deviation of a camera and a cutter point, and controlling the camera to respectively 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;
Obtaining offset compensation, and correcting the camera according to the offset compensation and the installation deviation;
the corrected camera is controlled to identify the positioning mark points on the cutting file according to the left and right outlines of the positioning mark points;
and correcting the coordinate value of the positioning mark point according to the identification result of the camera.
Preferably, the correcting the coordinate value of the positioning mark point according to the recognition result of the camera includes:
Acquiring an initial coordinate position of the preset positioning mark point;
Acquiring the actual coordinate position of the positioning mark point according to the identification result of the camera;
acquiring a deviation relation between the initial coordinate position and the actual coordinate position;
and correcting coordinate values of the point positioning coordinate point in the cutting file according to the deviation relation.
Preferably, the formula for obtaining offset compensation is:
offsetX=(cx-IMG_WIDTH/2)*ratio;
offseY=(cy-IMG_HEIGHT/2)*ratio;
wherein offsetX, offseY is the offset compensation value in the XY direction; cx and cy are the center coordinate values of the position of the tip of the nicking tool; img_width is a wide value of the real-time image data resolution, and img_high is a high value of the real-time image data resolution; ratio is the corresponding coefficient of camera pixel to actual distance.
Preferably, in the obtaining offset compensation, the correcting the camera according to the offset compensation and the installation deviation, the correcting the camera offset value is:
DeltaX’=DeltaX+offsetX;
DeltaY’=DeltaY+offsetY。
Preferably, the identifying, in the real-time image data after the binarization processing, left and right contours of positioning mark points in the real-time image data, and generating a cutting file includes:
defining a left profile array;
Traversing each row y of the real-time image data from top to bottom, 0< = y < img_width, wherein img_width is a wide value of the real-time image data resolution;
Traversing each column x,0< = x < img_head of the real-time image data from left to right, performing a judgment on a current point, wherein img_head is a high value of the real-time image data resolution;
If the current line does not find the left contour point yet and the previous point is white, the current point is black, and the current point is the left contour;
And saving the x coordinate value of the left outline, and updating the previous point to be the current point color value.
Preferably, the identifying, in the binarized real-time image data, left and right contours of positioning mark points in the real-time image data, and generating a cutting file further includes:
defining a right profile array;
Traversing each row y of the real-time image data from top to bottom, 0< = y < img_width, wherein img_width is a wide value of the real-time image data resolution;
traversing each column x,0< = x < img_head of the real-time image data from right to left, performing a judgment on a current point, wherein img_head is a high value of the real-time image data resolution;
if the current line does not find the right contour point yet and the previous point is white, the current point is black, and the current point is the right contour;
and storing the x coordinate value of the right outline, and updating the previous point to be the current point color value.
Preferably, when the decompression of a complete picture data is detected, the decompressed real-time image data is amplified and then displayed in real time on a display screen, and the amplifying of the decompressed real-time image data includes:
Traversing each row of the real-time image data, 0< = y < img_head, where img_head is a high value of the real-time image data resolution;
defining a temporary array for storing amplified data for each line of data;
Traversing each pixel point of the real-time image data, wherein 0< = x < img_width, wherein img_width is a wide value of the real-time image data resolution;
amplifying the row by a times;
and drawing the data of the row a after enlargement on the display screen.
In order to solve the technical problems, the application provides an MCU camera positioning device, which comprises:
the reading module is used for controlling the MCU to read real-time image data of the USB camera through the USB interface;
the decompression module is used for controlling the MCU to decompress the real-time image data of the USB camera;
The display control module is used for displaying decompressed real-time image data in a display screen in real time after the completion of the decompression of the whole picture data is detected;
The image processing module is used for carrying out binarization processing on the decompressed real-time image data;
The first identification module is used for identifying left and right outlines of positioning mark points in the real-time image data after binarization processing to generate a cutting file;
the mobile control module is used for acquiring the installation deviation of the camera and the cutter point, and controlling the camera to move a first distance DeltaX and a second distance DeltaY respectively in the XY direction of the real-time image data according to the installation deviation;
the correction module is used for acquiring offset compensation and correcting the camera according to the offset compensation and the installation deviation;
The second identification module is used for controlling the corrected camera to identify the positioning mark points on the cutting file according to the left and right outlines of the positioning mark points;
And the correction module is used for correcting the coordinate value of the positioning mark point according to the identification result of the camera.
In order to solve the technical problems, the present application provides an MCU camera positioning device, including: at least one processor, at least one memory and computer program instructions stored in the memory, which when executed by the processor, implement the method as in the first aspect of the embodiments described above.
To solve the above technical problem, the present application provides a storage medium having stored thereon computer program instructions which, when executed by a processor, implement a method as in the first aspect of the embodiments described above.
In summary, the embodiment of the invention provides a method, a device, equipment and a storage medium for positioning an MCU camera. The invention reads the real-time image data of the USB camera through the USB interface by controlling the MCU; controlling the MCU to decompress real-time image data of the USB camera; when the decompression of the complete picture data is detected, displaying the decompressed real-time image data in a display screen in real time; binarizing the decompressed real-time image data; identifying left and right outlines of positioning mark points in the real-time image data after binarization processing to generate a cutting file; acquiring the installation deviation of the camera and the tip of the nicking tool, and controlling the camera to move a first distance DeltaX and a second distance DeltaY respectively in the XY direction of real-time image data according to the installation deviation; obtaining offset compensation, and correcting the camera according to the offset compensation and the installation deviation; the corrected camera is controlled to identify the positioning mark points on the cutting file according to the left and right outlines of the positioning mark points; and correcting the coordinate value of the positioning mark point according to the identification result of the camera. Therefore, the invention realizes the accurate positioning of the camera on the carving machine, improves the carving precision, displays the image in real time and has low cost.
Drawings
In order to more clearly illustrate the technical solution of the embodiments of the present invention, the drawings that are needed to be used in the embodiments of the present invention will be briefly described, and other drawings can be obtained according to these drawings without inventive effort for a person skilled in the art.
Fig. 1 is a flowchart of a method for positioning an MCU camera according to an embodiment of the present invention.
Fig. 2 is a flowchart of a method for positioning an MCU camera according to an embodiment of the present invention.
Fig. 3 is a flowchart of a method for positioning an MCU camera according to an embodiment of the present invention.
Fig. 4 is a flowchart of a method for positioning an MCU camera according to an embodiment of the present invention.
Fig. 5 is a flowchart of a method for positioning an MCU camera according to an embodiment of the present invention.
Fig. 6 is a schematic outline diagram of a positioning mark point of an MCU camera positioning method according to an embodiment of the present invention.
Fig. 7 is a schematic diagram of a four-point positioning method of an MCU camera positioning method according to an embodiment of the present invention.
Fig. 8 is a diagram of the positional relationship between a camera and a tip of a nicking tool in the MCU camera positioning method according to the embodiment of the present invention.
Fig. 9 is a schematic structural diagram of an MCU camera positioning device according to an embodiment of the present invention.
Fig. 10 is a schematic structural diagram of an MCU camera positioning device according to an embodiment of the present invention.
Detailed Description
Features and exemplary embodiments of various aspects of the present invention will be described in detail below, and in order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention will be described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely configured to illustrate the invention and are not configured to limit the invention. It will be apparent to one skilled in the art that the present invention may be practiced without some of these specific details. The following description of the embodiments is merely intended to provide a better understanding of the invention by showing examples of the invention.
It is noted that relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Moreover, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
Referring to fig. 1, fig. 1 is a flowchart of an MCU camera positioning method according to the present application, including:
S1, controlling an MCU to read real-time image data of a USB camera through a USB interface;
s2, controlling the MCU to decompress real-time image data of the USB camera;
s3, after the fact that one piece of complete picture data is completely decompressed is detected, the decompressed real-time image data are displayed in a display screen in real time;
S4, binarizing the decompressed real-time image data;
S5, identifying left and right outlines of positioning mark points in the real-time image data after binarization processing, and generating a cutting file;
s6, acquiring the installation deviation of the camera and the cutter point, and controlling the camera to respectively 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;
S7, obtaining offset compensation, and correcting the camera according to the offset compensation and the installation deviation;
s8, controlling the corrected camera to identify positioning mark points on the cutting file according to the left and right outlines of the positioning mark points;
s9, correcting coordinate values of the positioning mark points according to the identification result of the camera.
In the prior art, a camera positioning scheme of the carving machine is responsible for image processing and positioning through an external special processing chip, and a processing result is transmitted to a master control MCU of the carving machine through a communication cable. The general camera needs to be arranged on the carving machine moving trolley, the main control MCU is fixed at the leftmost or rightmost end of the carving machine, the communication distance from the carving machine moving trolley to the carving machine main control MCU is long, the communication cable is easy to be interfered, and only a serial port communication mode can be selected generally. The speed of the serial port communication mode is limited, so that the traditional character carving machine has low speed of realizing the picture transmission by the camera positioning scheme and can not realize the real-time display of images; meanwhile, the scheme has high cost because of the need of externally connecting an image processing chip.
Aiming at the defects, the USB interface reads real-time image data of the USB camera; when the decompression of the complete picture data is detected, displaying the decompressed real-time image data in a display screen in real time; binarizing the decompressed real-time image data, and identifying left and right outlines of positioning mark points in the real-time image data to generate a cutting file; acquiring the installation deviation of the camera and the tip of the nicking tool, and controlling the camera to move a first distance DeltaX and a second distance DeltaY respectively in the XY direction of real-time image data according to the installation deviation; obtaining offset compensation, and correcting the camera according to the offset compensation and the installation deviation; the camera identifies the positioning mark points on the cutting file according to the left and right outlines of the positioning mark points; and the coordinate value of the positioning mark point is corrected according to the identification result of the camera, so that the accurate positioning of the camera on the carving machine is realized, the carving precision is improved, the image is displayed in real time, and the cost is low.
Specifically, the application aims to provide a camera positioning scheme which does not need to be externally connected with a special image processing chip and has low cost and real-time image display in a carving machine system taking an MCU as a main control. The MCU adopted in this embodiment is STM32F407, the main frequency is 168M, the memory is 196K, and the USB camera is externally connected through USB.
Specifically, the MCU serves as a USB host, and image data of the USB camera is read through a USB interface by adopting uvc communication protocols. It can be understood that the USB cable has strong anti-interference capability and high transmission speed, and is suitable for a real-time transmission scene of a picture stream.
Specifically, in uvc communication protocols, the picture format is an MPEG compression format, and the picture resolution is img_window. It is appreciated that MPEG compressed format picture processing frame rates are high compared to YUV non-compressed formats.
Specifically, the application adopts a double-buffer mode, and 2 large arrays are opened up in the memory to receive pictures. The receiving pointer uvc _ready_frame buffer_ptr points to the 1 st array, one frame of picture is received, the receiving pointer uvc _ready_frame buffer_ptr is immediately switched to the 2 nd array, and at the moment, the MCU takes picture data of the 1 st array to process; after the 2 nd array receives the picture data, the receiving pointer points to the 1 st array again, and the MCU starts to process the picture data in the 2 nd array. Therefore, the application has high data processing speed and can realize the real-time display of the image data.
Specifically, when the MCU decompresses the received MPEJ format picture data, since decompression is applied to the embedded scene, the memory needs to be reduced, so the present application selects TJpgDec library for decompression. TJpgDec is a decoding module for creating JPEG images, which is highly optimized by a small embedded system, and occupies low memory during operation so as to be integrated into an MCU chip.
TJpgDec the source compressed MJPEG data uvc _ready_framebuffer_ptr is input through the Api function jd_preparation, and the data is compressed through the jd_decomp Api function. The prototype of jd_decomp function is:
JRESULT jd_decomp(
JDEC*jd,
UINT(*outfunc)(JDEC*,void*,JRECT*),/*RGB output function*/
BYTE scale
)
the prototype of the output callback function outfunc is:
UINT output_func(JDEC*jd,void*bitmap,JRECT*rect)
The bitmap is the image data obtained by decompression, and rect is the length and width information of the image data. JRECT the structure includes left, right, top, bottom structures representing left edge coordinates, right edge coordinates, up edge coordinates, down edge coordinates, respectively, of the processed image. The rect parameter thus defines a rectangular block corresponding to a rectangular region of the image, the pixels of which are stored in the array bitmap. Since a source image is an image with img_width, img_heigh, and is output in a plurality of blocks after being decompressed by TJpgDec, the present application creates an array imgData with img_width, img_heigh, to collect decompressed data. The mapping relation between the bitmap array and the imgData array is as follows:
imgData[index2]=bitmap[index1]
index2=y*IMG_WIDTH+x,
index1=(right-left+1)*(y-top)+x
top<=y<=bottom
left<=x<=right
Wherein index2 is the index position of the picture mapped into the output picture imgData, and index1 is the index position of the picture in the small block bitmap. When it is detected that index2 is equal to img_width_heigh-1, the image processing may be started after the decompression of a frame of image is completed.
In summary, the application provides a positioning method of an MCU camera, in the scheme, real-time image data of the USB camera is read through a USB interface by controlling the MCU; controlling the MCU to decompress real-time image data of the USB camera; when the decompression of the complete picture data is detected, displaying the decompressed real-time image data in a display screen in real time; binarizing the decompressed real-time image data; identifying left and right outlines of positioning mark points in the real-time image data after binarization processing to generate a cutting file; acquiring the installation deviation of the camera and the tip of the nicking tool, and controlling the camera to move a first distance DeltaX and a second distance DeltaY respectively in the XY direction of real-time image data according to the installation deviation; obtaining offset compensation, and correcting the camera according to the offset compensation and the installation deviation; the corrected camera is controlled to identify the positioning mark points on the cutting file according to the left and right outlines of the positioning mark points; and correcting the coordinate value of the positioning mark point according to the identification result of the camera. Therefore, the application realizes the accurate positioning of the camera on the carving machine, improves the carving precision, displays the image in real time and has low cost.
Based on the above embodiments:
Referring to fig. 2, fig. 2 is a flowchart of an MCU camera positioning method according to the present application.
Referring to fig. 7, fig. 7 is a flowchart of an MCU camera positioning method according to the present application.
As a preferred embodiment, correcting the coordinate value of the positioning mark point according to the recognition result of the camera includes:
s91, acquiring an initial coordinate position of a preset positioning mark point;
S92, acquiring the actual coordinate position of the positioning mark point according to the identification result of the camera;
S93, acquiring a deviation relation between an initial coordinate position and an actual coordinate position;
s94, correcting coordinate values of the point positioning coordinate points in the cutting file according to the deviation relation.
Specifically, in order to realize accurate positioning and cutting of the carving machine, the carving machine prints positioning mark points on a cutting medium through a machine vision positioning technology before formally starting carving, and a camera transmits the coordinate positions of the positioning mark points to a carving machine main control MCU through identifying the coordinate positions of the positioning mark points, and the carving machine main control MCU executes carving actions on the appointed positions according to the positioning mark points.
Specifically, the application prints positioning mark points on a cutting medium by a four-point positioning method. After the corrected camera is controlled to identify the positioning mark points on the cutting file according to the left and right outlines of the positioning mark points, the cutting file can give out four mark points in the page to be cut. Taking the mark points as circles as an example, please refer to fig. 7, on the initial coordinate system XY, the centers of the four circle mark points are a (0, 0), B (W, 0), C (W, H), and D (0, H), respectively. The four marking circles are identified through a camera, the first circle center is set as A '(0, 0), the other three circle centers are respectively set as B' (xb ', yb'), C '(xc', yc '), D' (xd ', yd'), a 'B' C 'D' is located in a new coordinate system which is X 'Y', the rotation angle of the new coordinate system relative to the initial coordinate system is set as theta, the scaling ratio of the new coordinate system in the XY direction is set as a, B, and for one point (X, Y) in the XY coordinate system, the coordinate (X ', Y') converted into the X 'Y' coordinate system is as follows:
For the terms B '(xb', yb '), D' (xd ', yd'), there is an equation:
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:
therefore, the coordinate value of the positioning mark point is corrected according to the identification result of the camera, so that the coordinate value of the positioning mark point is more accurate, the camera on the engraving machine is accurately positioned, and the engraving precision is improved.
Referring to fig. 8, fig. 8 is a diagram illustrating a positional relationship between a camera and a tip of a nicking tool according to the MCU camera positioning method of the present application.
As a preferred embodiment, the formula for obtaining offset compensation is:
offsetX=(cx-IMG_WIDTH/2)*ratio;
offseY=(cy-IMG_HEIGHT/2)*ratio;
Wherein offsetX, offseY is the offset compensation value in the XY direction; cx and cy are the center coordinate values of the position of the tip of the nicking tool; img_width is a wide value of the real-time image data resolution, and img_head is a high value of the real-time image data resolution; ratio is the corresponding coefficient of camera pixel to actual distance.
As a preferred embodiment, in acquiring offset compensation, correcting the camera according to the offset compensation and the installation deviation, the camera offset value is corrected as follows:
DeltaX’=DeltaX+offsetX;
DeltaY’=DeltaY+offsetY。
Specifically, since the camera and the nicking tool are both mounted on the moving carriage of the nicking machine, the distance between the camera and the nicking tool is fixed, as shown in fig. 8. Before cutting starts, the tip faces the mark point, when photographing is needed, the distance value between the camera and the nicking tool on each mobile trolley is different due to the structural difference of the camera, and the photographing effect of the camera is affected by the error, so that the installation error is needed to be compensated through camera correction. The camera correction step comprises the following steps:
changing the tip of the carving tool into a thin nib, and drawing a small square on the carving medium, wherein the small square is used as a marking point;
according to the preset distance, the camera moves DeltaX and DeltaY in the XY direction respectively, runs to the position near the original knife tip to take a picture, and identifies a square;
and calculating offset compensation according to the recognized square circle center positions cx and cy, and correcting the camera.
The offset compensation value is:
offsetX=(cx-IMG_WIDTH/2)*ratio;
offseY=(cy-IMG_HEIGHT/2)*ratio;
Where ratio is the corresponding coefficient of camera pixel to actual distance.
The camera offset value is corrected as follows:
DeltaX’=DeltaX+offsetX;
DeltaY’=De l taY+offsetY。
referring to fig. 3, fig. 3 is a flowchart of an MCU camera positioning method according to the present application.
As a preferred embodiment, in the real-time image data after the binarization processing, identifying left and right contours of the positioning mark points in the real-time image data, generating the cutting file includes:
s51, defining a left profile array;
S52, traversing each row y of real-time image data from top to bottom, wherein 0< = y < IMG_WIDTH, wherein IMG_WIDTH is a wide value of the resolution of the real-time image data;
S53, traversing each column x,0< = x < IMG_HEIGHT of the real-time image data from left to right, and judging the current point, wherein IMG_HEIGHT is a high value of the resolution of the real-time image data;
s54, if the current line does not find the left contour point yet and the previous point is white, the current point is black, and the current point is the left contour;
s55, the x coordinate value of the left outline is saved, and the previous point is updated to be the current point color value.
Referring to fig. 4, fig. 4 is a flowchart of an MCU camera positioning method according to the present application.
As a preferred embodiment, in the real-time image data after the binarization processing, identifying left and right contours of the positioning mark points in the real-time image data, generating the cutting file further includes:
S51', defining a right profile array;
s52', traversing each row y of real-time image data from top to bottom, 0< = y < img_width, where img_width is a wide value of real-time image data resolution;
s53', traversing each column x,0< = x < img_head of the real-time image data from right to left, performing judgment on the current point, wherein img_head is a high value of the real-time image data resolution;
S54', if the current line does not find the right contour point yet and the previous point is white, the current point is black, and the current point is the right contour;
S55', the right outline x coordinate value is saved, and the previous point is updated to be the current point color value.
Referring to fig. 6, fig. 6 is a schematic outline diagram of a positioning mark point of the MCU camera positioning method according to the present application.
Specifically, marking points used for positioning the carving machine mainly comprise open squares and solid circles. The images identified by the present application are filled circles and open squares, as shown in fig. 6. First, a left and right contour array ColorArrLeft [ IMG_HEIGHT ] and ColorArrRight [ IMG_HEIGHT ] are defined, and the initial values of the array elements are all set to 0, which represents that no contour point has been found.
The method for identifying the left outline comprises the following steps:
Traversing each row y of the image from top to bottom, 0< = y < img_width;
Traversing each column x of the image from left to right, 0< = x < img_head, performing a decision on the current point:
if the current line has not found the left contour point (ColorArrLeft [ y ] = 0) and the previous point is white, the current point is black, the current point is the left contour, the current left contour abscissa value ColorArrLeft [ y ] = x is saved, and the previous point is updated to be the current point color value.
The right outline identification method comprises the following steps:
Traversing each row y of the image from top to bottom, 0< = y < img_width;
traversing each column x of the image from right to left, 0< = x < img_head, performing a decision on the current point:
If the current line has not found the right contour point (ColorArrRight [ y ] = 0) and the previous point is white and the current point is black, the current point is the right contour, the current right contour abscissa value ColorArrRight [ y ] = x is saved, and the previous point is updated to be the current point color value.
Specifically, when the square is identified, as the position of the square can ensure that two vertical edges of the square are basically parallel to the y axis, all left contour points need to be traversed, and coordinate values with highest occurrence probability of the abscissa are found out and are the left edge coordinates of the square; and traversing all right contour points in the same way, and finding out the coordinate value with the highest occurrence probability of the abscissa, wherein the coordinate value is the right coordinate value of the square.
Specifically, the steps of the square identification algorithm are as follows:
establishing TIMESLEFT [ IMG_WIDTH ] and TIMESRIGHT [ IMG_WIDTH ] arrays, and initializing all elements to 0;
Traversing all 0to img_head, 0< = i < img_head, performing the operation:
if ColorArrLeft [ i ] ] is ]! =0, then TIMESLEFT [ ColorArrLeft [ i ] ] ++;
If ColorArrRight [ i ] ] is ]! =0, then TIMESRIGHT [ ColorArrRight [ i ] ] ++;
Finding out the maximum value in ColorArrLeft arrays, wherein the corresponding index is the abscissa value meanLeft of the left edge of the square; finding out the maximum value in ColorArrRight arrays, wherein the corresponding index is the abscissa value MEANRIGHT of the right edge of the square, and calculating the width of the square with= MEANRIGHT-meanLeft; counting the number of points INLINELEFT of which all abscissa values are near meanLeft in the left outline, counting the number of points INLINERIGHT of which the abscissa values are near MEANRIGHT in the right outline, counting the number of left outline points countsLeft and counting the number of right outline points countsRight; counting the maximum value max_y of the ordinate and the minimum value min_y of the ordinate in the left outline, and calculating square height=max-min_y; when INLINELEFT/countsLeft >80% and INLINERIGHT/countsRight >80% and abs (width-height) < error value 5, then it is considered that a square is found and the square center coordinates cx= (meanLeft + MEANRIGHT)/2, cy= (max_y+min_y)/2 are calculated.
Specifically, the algorithm steps for identifying the circle are:
For the left contour, outliers are removed using a distance-based filtering method. The periphery of the circle is provided with a plurality of outliers, and the method for filtering the outliers comprises the following steps: and traversing all points in the left contour, calculating the distance between each point and other points in the contour, if the distance is smaller than a distance threshold value, then counting nearCount ++ by adjacent points, and if nearCount < a point threshold value finally, then considering the point as an outlier, and removing the outlier from the left contour point set.
For the left contour point set, a least square fitting is performed to obtain a circle center coordinate (cx, cy) and a radius r
For N point sets (x 1, y 1), (x 2, y 2), … …, (xn, yn), the formula for finding the center and radius by least squares is:
All points on the contour are traversed, the distances d between the points and the fitting circle centers (cx, cy) are calculated, if the absolute values of the distances d and r are smaller than a threshold value, the points are considered to be on the contour, and the number cirCnt of the points on the contour is increased by 1. And counts the number of counts of all contour points. After traversing, calculating the percentage cirCnt/count, and if cirCnt/count is more than 80%, considering that the circle identification is successful.
Referring to fig. 5, fig. 5 is a flowchart of an MCU camera positioning method according to the present application.
As a preferred embodiment, when it is detected that a complete picture data is decompressed, the decompressed real-time image data is enlarged and displayed on the display screen in real time, and the enlarging of the decompressed real-time image data includes:
S31, traversing each row of the real-time image data, wherein 0< = y < IMG_HEIGHT, wherein IMG_HEIGHT is a high value of the resolution of the real-time image data;
s32, defining a temporary array for storing amplified data for each row of data;
S33, traversing each pixel point of the real-time image data, wherein 0< = x < IMG_WIDTH, wherein IMG_WIDTH is a wide value of the resolution of the real-time image data;
s34, amplifying the row by a times;
S35, drawing the data of the enlarged line a on a display screen.
Specifically, when a complete picture is detected after decompression, the picture is displayed on the LCD screen. Because the img_width is smaller in the area of img_head, the application enlarges the length and WIDTH of the picture by 2 times and then displays the enlarged picture on the screen. The picture amplifying method comprises the following steps: traversing each line of the image, 0< = y < img_head; defining a temporary array color (IMG_WIDTH) for storing amplified data for each row of data, and traversing each pixel point 0< = x < IMG_WIDTH; amplifying the row by 2 times;
index=IMG_WIDTH*y+x
color[2*x]=imgData[index]
color[2*x+1]=imgData[index]
color[2*x+2*IMG_WIDTH]=imgData[index]
color [2 x+2 img_width ] = imgData [ index ]; drawing 2 lines of amplified data on a screen; and drawing 2 rows of pixels of 2 x y,2 x y+1 on the screen according to the color array.
Specifically, an image is subjected to image processing, and the image is converted into a gray scale image. Because the color format of the image decompressed by the MPEG is RGB565 format, for each 16-bit pixel color, R, G, B components are extracted first, then graying is carried out, and the graying value Gray is:
R=color>>11
B=color&0x1F
G=(color>>5)&0x3F
Gray=R*0.299+0.578*G+0.114*B。
Referring to fig. 9, fig. 9 is a block diagram of an MCU camera positioning device according to the present application.
The application also provides a MCU camera positioning device, which comprises:
The reading module 1 is used for controlling the MCU to read real-time image data of the USB camera through the USB interface;
the decompression module 2 is used for controlling the MCU to decompress the real-time image data of the USB camera;
the display control module 3 is used for displaying decompressed real-time image data in real time to a display screen after detecting that the decompression of one piece of complete picture data is finished;
an image processing module 4, configured to perform binarization processing on the decompressed real-time image data;
the first identifying module 5 is used for identifying left and right outlines of positioning mark points in the real-time image data after binarization processing to generate a cutting file;
The movement control module 6 is used for acquiring the installation deviation of the camera and the tip of the nicking tool, and controlling the camera to move a first distance DeltaX and a second distance DeltaY respectively in the XY direction of the real-time image data according to the installation deviation;
the correction module 7 is used for acquiring offset compensation and correcting the camera according to the offset compensation and the installation deviation;
the second identification module 8 is used for controlling the corrected camera to identify the positioning mark points on the cutting file according to the left and right outlines of the positioning mark points;
And the correction module 9 is used for correcting the coordinate value of the positioning mark point according to the identification result of the camera.
In addition, an MCU camera positioning method according to an embodiment of the present invention described in connection with fig. 1 may be implemented by an MCU camera positioning apparatus. Fig. 10 shows a schematic hardware structure of an MCU camera positioning device according to an embodiment of the present invention.
The MCU camera locating device may include a processor 401 and a memory 402 storing computer program instructions.
In particular, the processor 401 may include a Central Processing Unit (CPU), or an Application SPECIFIC INTEGRATED Circuit (ASIC), or may be configured as one or more integrated circuits that implement embodiments of the present invention.
Memory 402 may include mass storage for data or instructions. By way of example, and not limitation, memory 402 may comprise a hard disk drive (HARD DISK DRIVE, HDD), a floppy disk drive, flash memory, optical disk, magneto-optical disk, magnetic tape, or a universal serial bus (Universal Serial Bus, USB) drive, or a combination of two or more of the foregoing. Memory 402 may include removable or non-removable (or fixed) media, where appropriate. Memory 402 may be internal or external to the data processing apparatus, where appropriate. In a particular embodiment, the memory 402 is a non-volatile solid state memory. In a particular embodiment, the memory 402 includes Read Only Memory (ROM). The ROM may be mask programmed ROM, programmable ROM (PROM), erasable PROM (EPROM), electrically Erasable PROM (EEPROM), electrically rewritable ROM (EAROM), or flash memory, or a combination of two or more of these, where appropriate.
The processor 401 reads and executes the computer program instructions stored in the memory 402 to implement any one of the MCU camera positioning methods of the above embodiments.
In one example, the MCU camera locating device may also include a communication interface 403 and a bus 410. As shown in fig. 10, the processor 401, the memory 402, and the communication interface 403 are connected to each other by a bus 410 and perform communication with each other.
The communication interface 403 is mainly used to implement communication between each module, device, unit and/or apparatus in the embodiment of the present invention.
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 buses may include an Accelerated Graphics Port (AGP) or other graphics bus, an Enhanced Industry Standard Architecture (EISA) bus, a Front Side Bus (FSB), a HyperTransport (HT) interconnect, an Industry Standard Architecture (ISA) bus, an infiniband interconnect, a Low Pin Count (LPC) bus, a memory bus, a micro channel 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 standards association local (VLB) bus, or other suitable bus, or a combination of two or more of the above. Bus 410 may include one or more buses, where appropriate. Although embodiments of the invention have been described and illustrated with respect to a particular bus, the invention contemplates any suitable bus or interconnect.
In addition, in combination with the MCU camera positioning method in the above embodiment, the embodiment of the present invention may be implemented by providing a computer readable storage medium. The computer readable storage medium has stored thereon computer program instructions; the computer program instructions, when executed by the processor, implement any of the MCU camera positioning methods of the above embodiments.
It should also be noted that the exemplary embodiments mentioned in this disclosure describe some methods or systems based on a series of steps or devices. The present invention is not limited to the order of the above-described steps, that is, the steps may be performed in the order mentioned in the embodiments, or may be performed in a different order from the order in the embodiments, or several steps may be performed simultaneously.
In the foregoing, only the specific embodiments of the present invention are described, and it will be clearly understood by those skilled in the art that, for convenience and brevity of description, the specific working processes of the systems, modules and units described above may refer to the corresponding processes in the foregoing method embodiments, which are not repeated herein. It should be understood that the scope of the present invention is not limited thereto, and any equivalent modifications or substitutions can be easily made by those skilled in the art within the technical scope of the present invention, and they should be included in the scope of the present invention.
Claims (10)
1. The MCU camera positioning method is characterized by comprising the following steps:
the control MCU reads real-time image data of the USB camera through the USB interface;
controlling the MCU to decompress real-time image data of the USB camera;
When the decompression of the complete picture data is detected, displaying the decompressed real-time image data in a display screen in real time;
Performing binarization processing on the decompressed real-time image data;
identifying left and right contours of positioning mark points in the real-time image data after binarization processing to generate a cutting file;
Acquiring the installation deviation of a camera and a cutter point, and controlling the camera to respectively 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;
Obtaining offset compensation, and correcting the camera according to the offset compensation and the installation deviation;
the corrected camera is controlled to identify the positioning mark points on the cutting file according to the left and right outlines of the positioning mark points;
and correcting the coordinate value of the positioning mark point according to the identification result of the camera.
2. The method for positioning an MCU camera according to claim 1, wherein said correcting the coordinate value of the positioning mark point according to the recognition result of the camera comprises:
Acquiring an initial coordinate position of the preset positioning mark point;
Acquiring the actual coordinate position of the positioning mark point according to the identification result of the camera;
acquiring a deviation relation between the initial coordinate position and the actual coordinate position;
and correcting coordinate values of the point positioning coordinate point in the cutting file according to the deviation relation.
3. The method for positioning an MCU camera according to claim 1, wherein the formula for obtaining offset compensation is:
offsetX=(cx-IMG_WIDTH/2)*ratio;
offseY=(cy-IMG_HEIGHT/2)*ratio;
Wherein offsetX, offseY is the offset compensation value in the XY direction; cx and cy are the center coordinate values of the position of the tip of the nicking tool; img_width is a wide value of the real-time image data resolution, and img_high is a high value of the real-time image data resolution; ratio is the corresponding coefficient of camera pixel to actual distance.
4. The MCU camera positioning method of claim 2, wherein in the obtaining offset compensation, the camera is corrected according to the offset compensation and the installation deviation, the camera offset value is corrected as follows:
DeltaX’=DeltaX+offsetX;
DeltaY’=DeltaY+offsetY。
5. The method for positioning an MCU camera according to claim 1, wherein identifying left and right contours of positioning mark points in the real-time image data after binarization processing, generating a cut file includes:
defining a left profile array;
Traversing each row y of the real-time image data from top to bottom, 0< = y < img_width, wherein img_width is a wide value of the real-time image data resolution;
Traversing each column x,0< = x < img_head of the real-time image data from left to right, performing a judgment on a current point, wherein img_head is a high value of the real-time image data resolution;
If the current line does not find the left contour point yet and the previous point is white, the current point is black, and the current point is the left contour;
And saving the x coordinate value of the left outline, and updating the previous point to be the current point color value.
6. The method for positioning an MCU camera according to claim 5, wherein identifying left and right contours of positioning mark points in the real-time image data after binarization processing, generating a cut file further comprises:
defining a right profile array;
Traversing each row y of the real-time image data from top to bottom, 0< = y < img_width, wherein img_width is a wide value of the real-time image data resolution;
traversing each column x,0< = x < img_head of the real-time image data from right to left, performing a judgment on a current point, wherein img_head is a high value of the real-time image data resolution;
if the current line does not find the right contour point yet and the previous point is white, the current point is black, and the current point is the right contour;
and storing the x coordinate value of the right outline, and updating the previous point to be the current point color value.
7. The method for positioning an MCU camera according to claim 1, wherein when it is detected that a complete picture data is decompressed, the decompressed real-time image data is amplified and displayed on the display screen in real time, and the amplifying of the decompressed real-time image data includes:
Traversing each row of the real-time image data, 0< = y < img_head, where img_head is a high value of the real-time image data resolution;
defining a temporary array for storing amplified data for each line of data;
Traversing each pixel point of the real-time image data, wherein 0< = x < img_width, wherein img_width is a wide value of the real-time image data resolution;
amplifying the row by a times;
and drawing the data of the row a after enlargement on the display screen.
8. An MCU camera positioner, the device comprising:
the reading module is used for controlling the MCU to read real-time image data of the USB camera through the USB interface;
the decompression module is used for controlling the MCU to decompress the real-time image data of the USB camera;
The display control module is used for displaying decompressed real-time image data in a display screen in real time after the completion of the decompression of the whole picture data is detected;
The image processing module is used for carrying out binarization processing on the decompressed real-time image data;
The first identification module is used for identifying left and right outlines of positioning mark points in the real-time image data after binarization processing to generate a cutting file;
the mobile control module is used for acquiring the installation deviation of the camera and the cutter point, and controlling the camera to move a first distance DeltaX and a second distance DeltaY respectively in the XY direction of the real-time image data according to the installation deviation;
the correction module is used for acquiring offset compensation and correcting the camera according to the offset compensation and the installation deviation;
The second identification module is used for controlling the corrected camera to identify the positioning mark points on the cutting file according to the left and right outlines of the positioning mark points;
And the correction module is used for correcting the coordinate value of the positioning mark point according to the identification result of the camera.
9. MCU camera positioning apparatus, characterized by comprising: at least one processor, at least one memory, and computer program instructions stored in the memory, which when executed by the processor, implement the method of any one of claims 1-7.
10. A storage medium having stored thereon computer program instructions, which when executed by a processor, implement the method of any of claims 1-7.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210501188.2A CN114913240B (en) | 2022-05-09 | 2022-05-09 | A MCU camera positioning method, device, equipment and storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210501188.2A CN114913240B (en) | 2022-05-09 | 2022-05-09 | A MCU camera positioning method, device, equipment and storage medium |
Publications (2)
Publication Number | Publication Date |
---|---|
CN114913240A CN114913240A (en) | 2022-08-16 |
CN114913240B true CN114913240B (en) | 2024-11-22 |
Family
ID=82765981
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202210501188.2A Active CN114913240B (en) | 2022-05-09 | 2022-05-09 | A MCU camera positioning method, device, equipment and storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN114913240B (en) |
Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111279231A (en) * | 2017-10-27 | 2020-06-12 | 住友化学株式会社 | Polarizing film and method for producing same |
CN113920038A (en) * | 2021-09-13 | 2022-01-11 | 环盛智能(深圳)有限公司 | A cutting contour extraction method, device system and medium |
Family Cites Families (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
DE50206199D1 (en) * | 2002-08-02 | 2006-05-18 | Hell Gravure Systems Gmbh | Method for improving the quality of an image engraved in a printing form cylinder |
CN114103506B (en) * | 2021-09-28 | 2023-04-21 | 环盛智能(深圳)有限公司 | Mobile phone rear film printing and cutting method |
-
2022
- 2022-05-09 CN CN202210501188.2A patent/CN114913240B/en active Active
Patent Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111279231A (en) * | 2017-10-27 | 2020-06-12 | 住友化学株式会社 | Polarizing film and method for producing same |
CN113920038A (en) * | 2021-09-13 | 2022-01-11 | 环盛智能(深圳)有限公司 | A cutting contour extraction method, device system and medium |
Also Published As
Publication number | Publication date |
---|---|
CN114913240A (en) | 2022-08-16 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN110751682B (en) | Method, device, terminal equipment and storage medium for extracting and identifying image | |
CN108133216B (en) | Nixie tube reading identification method capable of realizing decimal point reading based on machine vision | |
CN108416355B (en) | A collection method of industrial field production data based on machine vision | |
CN108965839B (en) | Method and device for automatically adjusting projection picture | |
CN108875855B (en) | Method, device, equipment and storage medium for printing vector diagram | |
CN113592839B (en) | Distribution network line typical defect diagnosis method and system based on improved fast RCNN | |
CN114494017A (en) | Method, device, equipment and medium for adjusting DPI (deep packet inspection) image according to scale | |
CN112288049B (en) | Pointer meter reading method based on template matching and limitation of connected domain pointer positioning | |
CN115512381A (en) | Text recognition method, text recognition device, text recognition equipment, storage medium and working machine | |
CN114926786A (en) | Ship water gauge tracking method and device, storage medium and electronic equipment | |
JP7262927B2 (en) | Image processing device, image processing method and program | |
CN110969135B (en) | Vehicle logo recognition method in natural scene | |
CN114913240B (en) | A MCU camera positioning method, device, equipment and storage medium | |
CN115830018A (en) | Carbon block detection method and system based on deep learning and binocular vision | |
CN116985873A (en) | Rail transit station track section occupation state detection method | |
CN118520893A (en) | Method, device and storage medium for identifying bar code label applied to AOI | |
CN109141457B (en) | Navigation evaluation method and device, computer equipment and storage medium | |
CN106413280A (en) | Automatic surface mounting machine feeder element position correction device and automatic correction method based on image processing | |
CN115082552B (en) | Marking hole positioning method and device, assembly equipment and storage medium | |
CN113139394A (en) | Code reading method, electronic device and storage medium | |
CN103136543B (en) | Image processing apparatus and image processing method | |
CN114677373A (en) | Printed matter content error detection method and device, electronic equipment and medium | |
CN117372937B (en) | Data reading method based on pointer instrument | |
CN118660145B (en) | Security check image conversion method, system, equipment and storage medium | |
CN112950623A (en) | Mark identification method and system |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |