Dear Huggingface community and @John6666 @Alanturner2 or maybe @Nafnlaus
I was gonna rotate my images but rotating with just PIL.Image.rotate(degree)
will rotate with black area around it. So I try to find a method then I found out that I need to make a contour of the image to make it fit into the “frame” or so I think it was.
When I apply it with my image, the image asks for CV_8UC1
with error like this
---------------------------------------------------------------------------
error Traceback (most recent call last)
Cell In[22], line 23
20 morphed_resized = (morphed > 0.5).astype(np.uint8) * 255
22 # Find the max-area contour
---> 23 cnts = cv2.findContours(morphed_resized, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[-2]
24 cnt = sorted(cnts, key=cv2.contourArea)[-1]
26 ## This will extract the rotated rect from the contour
error: OpenCV(4.10.0) D:\a\opencv-python\opencv-python\opencv\modules\imgproc\src\contours_new.cpp:330: error: (-2:Unspecified error) in function 'class std::shared_ptr<struct ContourScanner_> __cdecl ContourScanner_::create(class cv::Mat,int,int,class cv::Point_<int>)'
> Modes other than RETR_FLOODFILL and RETR_CCOMP support only CV_8UC1 images (expected: 'img.type() == CV_8UC1'), where
> 'img.type()' is 16 (CV_8UC3)
> must be equal to
> 'CV_8UC1' is 0 (CV_8UC1)
A little googling let me finds out that CV_8UC1
are image format as written onhere, and here. Basically from those two I need to convert the image into the same channel needed by cv2.findContours
that, according to its documentation, requires binary image
. Is that what CV_8UC1
are?
Oh wait, can I do it with same method as before like
.convert("L")) / 255
? The guide did it like
morphed_resized = (morphed > 0.5).astype(np.uint8) * 255
but no avail, the error persists.
Hmm maybe I should try with the dividing it with 255 to make it relative to black and white too. Am I doing this correctly? In a minute by trying that