I am looking for a flawless algorithm for defining 4 points document edge detection for a reward.

I need an algorithm using OpenCV (sequence of actions) for accurate and high-quality determination of 4 points of the document. I experimented for a long time with a huge number of solutions that I found on the Internet, using functions such as (cv.threshold, cv.normalize, cv.GaussianBlur, cv.dilate, cv.Canny, cv.HoughLines, cv.morphologyEx, cv.findContours, cv.contourArea, cv.arcLength, cv.approxPolyDP etc.), I tried various approaches, such as blur, erosion, search for contours with further interpolation, Hough lines, with additional filtering, and also tried to mix these approaches. I tried to play with the parameters of each function an infinite number of times and it gave some result, but it is far from the result that programs such as ScannerPro, GeniusScan or CamScanner. Algorithms that end up looking for contours work well against a dark background, while algorithms that end up using Hough lines give a very unstable result (in real time, the frame is constantly jumping from side to side). I need an algorithm that will work stably regardless of the conditions in which the photo is taken. The algorithm must be lightweight in order to be able to get the frame in real time. I’m not interested in the algorithms that are freely available on the github. I’ve already tried absolutely everything that is possible. I also need a completely viable solution that will work under any conditions and it should be at the level of professional programs. Also, do not offer me ready-made subscription solutions, such as the Scanbot SDK or GeniusScan SDK. The algorithm is what I need. I am ready to discuss the reward.