Circle Detection Issues

I don’t have experience with that particular lens, but some comments:

  1. It’s a very fast lens (f1.4) which is great for light gathering, but such a large (small numerical) aperture will reduce your depth of field, so maybe that’s why you are having focusing problems (particularly if your object has some depth to it)
  2. I don’t see a minimum object distance in the specs for that lens, but in my experience 40mm would be very close. Most of the lenses I use have a MOD of 10cm or more. If I understand correctly you were having trouble focusing at 40mm distance with your wide angle (original) lens - this doesn’t surprise me. I also think you might have trouble at 40mm with the lens you ordered (again, I didn’t see that listed in the specs)
  3. The 1.3MP lens might be fine for you, especially since you are using 720p resolution, but in my experience higher optical resolution is almost always better. First of all the manufacturers tend to overstate the optical resolution - maybe picking the central area of the lens for their test, and not telling you that it’s much worse at the edges. I use a 3MP sensor and can tell a significant difference between the 5MP lens we use for some products and the 12MP lens we use for others. They are similar FOV, but the 12MP lens produces a much better and more consistent image. It’s not just the optical resolution, it’s a better designed / more sophisticated lens. It’s also about 6x the cost ($25 vs $4 in volume)
  4. This is a secondary consideration, but you should keep it on your radar. The chief ray angle varies from lens to lens - roughly speaking it is the angle of incidence of the light on the sensor - this is important because sensors are designed to work with certain CRA ranges, and if you get a bad mismatch your image quality will suffer. I’m not an expert on it, but I think a mismatch will result in vignetting, color shifts and sharpness - probably affecting the perimeter more than the central part of the image.
  5. If you have trouble finding a lens that will focus at 40mm, consider moving the camera further away and either accepting the larger imaged area, or selecting a lens with an even longer focal length.

The best supplier I have found is AICO in China. They do sell small quantity samples, but with shipping etc. the prices might be high. Also they are oriented at volume buyers, so they might not work with you:

They are pretty expensive as “lenses from China” go, but they are the best I have found.

If I get a chance I will look through my lens library and see if I can recommend something. Are you able to change the mount on the camera? Is it a plastic mount with two mounting screws? 18mm spacing? 20? 22? I ask because the lenses I have used with a close focusing distance are M8 lenses, so they require a different mount.

Edit: The OV2710 appears to have a CRA of 23.6 deg (I didn’t see a CRA spec for the lens you ordered)

Why chief ray angle matters: https://www.opticsdan.com/post/__cra