I would recommend having a look at the ESP32Cam modules, they can be programmed with the Arduino IDE and are very cheap.
The camera goes up to a resolution of 1600x1200 although you will find if capturing the image as RGB you are limited to 1280x1024 as you are limited by the available memory to store all the data.
If you search eBay for “esp32cam-mb” you can get one along with a motherboard for under £10 and this makes programming them easier as they do not have USB Serial built in (note I have found I have to reduce the serial port speed to get mine to work).
If you have a look at my sketch Here: ESP32Cam demo sketch
it shows how you can get raw data from the camera image and from this you could create your code to extract information from the image. The data in my example is in RGB format but you can capture Greyscale images which would probably simplify your task ?
Your code could be as simple as just looking from each side of the image for a sudden high change in brightness and measuring the distance between them.
The ESP32 is surprisingly powerful so should be able to do what you require although another option would be to get the camera to send data over the serial port in to Processing and do the image manipulation on the PC.
For lots of insparation/examples of working with images in Processing have a look at this Youtube channel: Coding Train