1. An image processing apparatus comprising at least one hardware processor configured to implement: a difference detector that detects a difference between two images according to a set detection condition; a receiving part that receives the two images as comparison targets and a target difference image that is desirable in difference detection of the two images; and a setting part that selects a detection condition from a plurality of predetermined detection conditions and sets the selected detection condition in the difference detector, the selected detection condition causing a difference image that is acquired by the difference detector from the two images received by the receiving part to be closer to the target difference image, wherein the setting part selects, from the predetermined detection conditions, a detection condition that reduces a difference between a number of pixels in a difference region in the target difference image and a number of pixels in a difference region in the difference image detected by the difference detector and sets the selected detection condition in the difference detector.