My goal is to find a piece of white paper from this binary image, and then crop this white paper and create a new subset of the binary image for this white paper only.

Now my Python code with OpenCV can find this white document. In the first step, I created a mask to search for this white paper:

As you guys see, a little white noise and a small part have been removed. And then the problem is, how can I crop this white document from this binary image to create a new subset of the binary image?
My current code is:
import cv2
import numpy as np
QR = cv2.imread('IMG_0352.TIF', 0)
mask = np.zeros(QR.shape,np.uint8)
contours, hierarchy = cv2.findContours(QR,cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)
for cnt in contours:
if cv2.contourArea(cnt)>1000000:
cv2.drawContours(mask,[cnt],0,255,-1)
We are looking for cnt var, there are four elements, but for me this is nonsense. I used the code to set the window:
x,y,w,h = cv2.boundingRect(cnt)
cv2.rectangle(img,(x,y),(x+w,y+h),(0,255,0),2)
The box information seems to be incorrect.
.
:
, . :
import cv2
import numpy as np
QR_orig = cv2.imread('CamR_IMG_0352.TIF', 0)
QR = cv2.imread('IMG_0352.TIF', 0)
mask = np.zeros(QR.shape,np.uint8)
contours, hierarchy = cv2.findContours(QR,cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)
for cnt in contours:
if cv2.contourArea(cnt)>1000000:
cv2.drawContours(mask,[cnt],0,255,-1)
x,y,w,h = cv2.boundingRect(cnt)
roi=mask[y:y+h,x:x+w]
QR_crop = QR_orig[y:y+h,x:x+w]
QR_final = QR_crop * (roi/255)
cv2.imwrite('QR_final.TIF', QR_final)