Basic CPP code
You need a 2 pound Coin for calibration, can be adjusted according to the need, by changing the calibration values. change the resolution before starting the program and add the openCV headers.
let me know if there is any optimisation can be done.