An image processing sensor for performing predetermined image processing on an image of an inspection target object to detect that the inspection target object is a non-defective product or a defective product, wherein the image processing sensor is configured to be switched to an operation mode for performing pass/fail determination of the non-defective product and the defective product and a setting mode for performing setting of a matching degree threshold serving as a reference in the pass/fail determination of the non-defective product and the defective product, the image processing sensor comprising: an imaging unit configured to image the inspection target object; a pass/fail determining unit configured to perform, on the basis of an input image of the inspection target object acquired by the imaging unit, the pass/fail determination in the operation mode for distinguishing the inspection target object as a non-defective product or a defective product, using the matching degree threshold serving as the reference of the pass/fail determination and comparing a matching degree of the input image with the matching degree threshold; an image registering unit configured to, in the setting mode, acquire, with the imaging unit, an image including the inspection target object that should be distinguished as the non-defective product by the pass/fail determining unit in front of a background, and register the image as a non-defective product image, acquire, with the imaging unit, an image including the inspection target object that should be distinguished as the defective product by the pass/fail determining unit in front of the background, and register the image as a defective product image, and acquire, with the imaging unit, an image of the background and register the image as a background image; a differential-image generating unit configured to, in the setting mode, generate a first differential image from the non-defective product image and the background image registered by the image registering unit, wherein the background is excluded from the non-defective product image, and generate a second differential image from the defective product image and the background image registered by the image registering unit, wherein the background is excluded from the defective product image; a matching-degree calculating unit configured to calculate, in the setting mode, a matching degree indicating a degree of matching of the second differential image with respect to a model image corresponding to the first differential image generated by the differential-image generating unit, and configured to calculate, in the operation mode, the matching degree of the input image, indicating a degree of matching of the input image to the model image; and a threshold calculating unit configured to set the matching degree threshold used in the operation mode on the basis of the matching degree calculated by the matching-degree calculating unit in the setting mode, wherein the threshold is a numerical value greater than the matching degree calculated by the matching-degree calculating unit in the setting mode. an imaging unit configured to image the inspection target object; a pass/fail determining unit configured to perform, on the basis of an input image of the inspection target object acquired by the imaging unit, the pass/fail determination in the operation mode for distinguishing the inspection target object as a non-defective product or a defective product, using the matching degree threshold serving as the reference of the pass/fail determination and comparing a matching degree of the input image with the matching degree threshold; an image registering unit configured to, in the setting mode, acquire, with the imaging unit, an image including the inspection target object that should be distinguished as the non-defective product by the pass/fail determining unit in front of a background, and register the image as a non-defective product image, acquire, with the imaging unit, an image including the inspection target object that should be distinguished as the defective product by the pass/fail determining unit in front of the background, and register the image as a defective product image, and acquire, with the imaging unit, an image of the background and register the image as a background image; a differential-image generating unit configured to, in the setting mode, generate a first differential image from the non-defective product image and the background image registered by the image registering unit, wherein the background is excluded from the non-defective product image, and generate a second differential image from the defective product image and the background image registered by the image registering unit, wherein the background is excluded from the defective product image; a matching-degree calculating unit configured to calculate, in the setting mode, a matching degree indicating a degree of matching of the second differential image with respect to a model image corresponding to the first differential image generated by the differential-image generating unit, and configured to calculate, in the operation mode, the matching degree of the input image, indicating a degree of matching of the input image to the model image; and a threshold calculating unit configured to set the matching degree threshold used in the operation mode on the basis of the matching degree calculated by the matching-degree calculating unit in the setting mode, wherein the threshold is a numerical value greater than the matching degree calculated by the matching-degree calculating unit in the setting mode.