What is claimed is:
1. A code reader that reads a code attached to a workpiece, the code reader comprising:
an illumination unit that irradiates the workpiece with illumination light;
an imaging unit that includes a Scheimpflug optical system including a lens collecting reflected light from the code attached to the workpiece and an image sensor having a light receiving surface inclined with respect to an optical axis of the lens, the imaging unit generating and outputting a code image including the code based on an amount of received light received by the light receiving surface;
a decoding unit that executes decoding processing on the code image; and
a control unit that associates a decoded code with the workpiece,
wherein
the Scheimpflug optical system has a visual field range, within which a depth-of-field region is tilted relative to the optical axis and intersects the optical axis at a predetermined angle,
the control unit calculates an index for evaluating whether or not a code to which the decoding processing has been applied is a code that has been decoded in the depth-of-field region, and determines an accuracy of an association of the decoded code with the workpiece based on the calculated index, and
when the control unit determines that the decoded code was not decoded within the depth-of-field region, the control unit determines that the association of the decoded code with the workpiece is inaccurate.
2. The code reader according to claim 1 , wherein
the imaging unit captures images of a plurality of the workpieces moving adjacent to each other on a conveyor to generate the code image in which a plurality of the codes including the codes respectively attached to the plurality of workpieces appear, and
the control unit specifies a target workpiece located in the depth-of-field region at a point in time when the code image is captured, calculates the index based on information obtained from the code image, and determines that an association of a code, evaluated to have a relatively high possibility of having been decoded in the depth-of-field region, with the target workpiece is accurate based on the index.
3. The code reader according to claim 1 , wherein the control unit calculates the index in such a manner that a possibility that the code to which the decoding processing has been applied in the code image is the code that has been decoded in the depth-of-field region increases as a differential value between luminance values of the code image is larger or as a difference between a maximum value and a minimum value of luminance values in a partial region of the code image is larger.
4. The code reader according to claim 1 , wherein the control unit calculates the index in such a manner that a possibility that the code to which the decoding processing has been applied in the code image is the code that has been decoded in the depth-of-field region increases as a luminance value of the code image increases.
5. The code reader according to claim 1 , wherein the control unit calculate the index in such a manner that a possibility that the code to which the decoding processing has been applied in the code image is the code that has been decoded in the depth-of-field region is high in a case where at least a part of the workpiece is included in the depth-of-field region at a point in time when the code image is captured.
6. The code reader according to claim 5 , wherein the control unit calculates the index in such a manner that the possibility that the code to which the decoding processing has been applied is the code that has been decoded in the depth-of-field region is high in a case where a specific position of the workpiece is included in the depth-of-field region.
7. The code reader according to claim 1 , wherein the control unit calculates the index in such a manner that a possibility that the code to which the decoding processing has been applied is the code that has been decoded in the depth-of-field region increases as a shape of the code is closer to a rectangle.
8. The code reader according to claim 1 , wherein
the control unit calculates the index based on contrast of the code image, and
the control unit calculates the index in such a manner that a possibility that the code to which the decoding processing has been applied is the code that has been decoded in the depth-of-field region increases as the contrast is higher.
9. The code reader according to claim 1 , wherein the control unit calculates the index based on a temporal change of the code image.
10. The code reader according to claim 1 , wherein the control unit calculates the index based on an amount of high frequency components of the code image.
11. The code reader according to claim 1 , wherein
the control unit calculates the index based on a change between a first code image and a second code image generated after the first code image,
calculates the index in such a manner that a possibility that a code of the second code image is the code that has been decoded in the depth-of-field region increases as high frequency components of the second code image are more than high frequency components of the first code image, and
calculates the index in such a manner that the possibility that the code of the second code image is the code that has been decoded in the depth-of-field region decreases as the high frequency components of the second code image are fewer than the higher frequency components of the first code image.
12. The code reader according to claim 1 , the code reader being configured to be capable of outputting an error signal in a case where the control unit determines that the code is associated with the wrong workpiece.
13. The code reader according to claim 1 , wherein
the imaging unit includes an aperture adjustment mechanism, and is configured to be capable of changing the depth-of-field region formed by the Scheimpflug optical system by adjusting an amount of aperture using the aperture adjustment mechanism, and
the control unit calculates the index based on the depth-of-field region according to the amount of aperture.
14. A code reading method of reading a code attached to a workpiece, the code reading method comprising:
an illumination step of irradiating a workpiece with illumination light;
an imaging step of capturing an image of the workpiece by an imaging unit, which includes a Scheimpflug optical system including a lens collecting reflected light from the code attached to the workpiece and an image sensor having a light receiving surface inclined with respect to an optical axis of the lens, and generating and outputting a code image including the code based on an amount of received light received by the light receiving surface;
a decoding step of performing decoding processing on the code image;
an associating step of associating a decoded code with the workpiece;
a calculation step of calculating, based on a result of the decoding processing, an index for evaluating whether or not a code to which the decoding processing has been applied is a code that has been decoded in a depth-of-field region; and
a determination step of determining an accuracy of an association of the decoded code with the workpiece based on the index calculated in the calculation step, wherein
the Scheimpflug optical system has a visual field range, within which a depth-of-field region is tilted relative to the optical axis and intersects the optical axis at a predetermined angle, and
when the determination step determines that the decoded code was not decoded within the depth-of-field region, the determination step determines that the asso