# Less trouble reading/writing images with OpenCV

```python
from a_cv_imwrite_imread_plus import add_imwrite_plus_imread_plus_to_cv2
add_imwrite_plus_imread_plus_to_cv2()
cv2.imwrite_plus("f:\\ö\\ö\\ö\\öädssdzß.jpg", base64img2cv)

#or:
from a_cv_imwrite_imread_plus import save_cv_image
save_cv_image("f:\\ö\\ö\\ö\\öädssdzß.jpg", base64img2cv)


	Parameters:
		filepath:str
			folders will be created if they don't exist
		image:np.ndarray
			image as np
	Returns:
		filepath:str
```


```python
from a_cv_imwrite_imread_plus import add_imwrite_plus_imread_plus_to_cv2
add_imwrite_plus_imread_plus_to_cv2()
import base64
from PIL import Image
import cv2

#Base64
base64img = r"data:image/png;base64, "
base64img2 = r" "
base64imgcv = cv2.imread_plus(base64img)
base64img2cv = cv2.imread_plus(base64img2)
base64imgcv = cv2.imread_plus(base64img, channels_in_output=4)
base64img2cv = cv2.imread_plus(base64img2, channels_in_output=4)
base64imgcv = cv2.imread_plus(base64img, channels_in_output=2)
base64img2cv = cv2.imread_plus(base64img2, channels_in_output=2)

#urls
pininterestlogo = "https://camo.githubusercontent.com/7f81f312b05694ccc8cd29e3c3466945ff8e73a13320d3fd0f90c6915bbb4ffb/68747470733a2f2f63646e2e6a7364656c6976722e6e65742f67682f646d68656e647269636b732f7369676e61747572652d736f6369616c2d69636f6e732f69636f6e732f726f756e642d666c61742d66696c6c65642f353070782f70696e7465726573742e706e67"
linkcv1 = cv2.imread_plus(pininterestlogo)
linkcv2 = cv2.imread_plus(pininterestlogo, channels_in_output=4)
linkcv3 = cv2.imread_plus(pininterestlogo, channels_in_output=2)
linkcv4 = cv2.imread_plus(pininterestlogo, channels_in_output=3)

#bytes/raw data
byteimage = base64.b64decode(base64img2)
byteimage1 = cv2.imread_plus(byteimage)
byteimage2 = cv2.imread_plus(byteimage, channels_in_output=4)
byteimage3 = cv2.imread_plus(byteimage, channels_in_output=2)
byteimage4 = cv2.imread_plus(byteimage, channels_in_output=3)

#PIL
pilimage = Image.fromarray(byteimage2)
pilimage1 = cv2.imread_plus(pilimage)
pilimage2 = cv2.imread_plus(pilimage, channels_in_output=4)
pilimage3 = cv2.imread_plus(pilimage, channels_in_output=2)
pilimage4 = cv2.imread_plus(pilimage, channels_in_output=3)

#float images to np.uint8
floatimage = pilimage4.astype(float)
floatimage1 = cv2.imread_plus(floatimage)
floatimage2 = cv2.imread_plus(floatimage, channels_in_output=4)
floatimage3 = cv2.imread_plus(floatimage, channels_in_output=2)
floatimage4 = cv2.imread_plus(floatimage, channels_in_output=3)

#filepath
filepath = "c:\\testestestes.png"
pilimage.save(filepath)
filepath1 = cv2.imread_plus(filepath, bgr_to_rgb=True)
filepath2 = cv2.imread_plus(filepath, channels_in_output=4, bgr_to_rgb=True)
filepath3 = cv2.imread_plus(filepath, channels_in_output=2, bgr_to_rgb=True)
filepath4 = cv2.imread_plus(filepath, channels_in_output=3, bgr_to_rgb=True)



#or:
from a_cv_imwrite_imread_plus import open_image_in_cv
#Base64
base64img = r"data:image/png;base64, "
base64img2 = r" "
base64imgcv = open_image_in_cv(base64img)
base64img2cv = open_image_in_cv(base64img2)
base64imgcv = open_image_in_cv(base64img, channels_in_output=4)
base64img2cv = open_image_in_cv(base64img2, channels_in_output=4)
base64imgcv = open_image_in_cv(base64img, channels_in_output=2)
base64img2cv = open_image_in_cv(base64img2, channels_in_output=2)

#urls
pininterestlogo = "https://camo.githubusercontent.com/7f81f312b05694ccc8cd29e3c3466945ff8e73a13320d3fd0f90c6915bbb4ffb/68747470733a2f2f63646e2e6a7364656c6976722e6e65742f67682f646d68656e647269636b732f7369676e61747572652d736f6369616c2d69636f6e732f69636f6e732f726f756e642d666c61742d66696c6c65642f353070782f70696e7465726573742e706e67"
linkcv1 = open_image_in_cv(pininterestlogo)
linkcv2 = open_image_in_cv(pininterestlogo, channels_in_output=4)
linkcv3 = open_image_in_cv(pininterestlogo, channels_in_output=2)
linkcv4 = open_image_in_cv(pininterestlogo, channels_in_output=3)

#bytes/raw data
byteimage = base64.b64decode(base64img2)
byteimage1 = open_image_in_cv(byteimage)
byteimage2 = open_image_in_cv(byteimage, channels_in_output=4)
byteimage3 = open_image_in_cv(byteimage, channels_in_output=2)
byteimage4 = open_image_in_cv(byteimage, channels_in_output=3)

#PIL
pilimage = Image.fromarray(byteimage2)
pilimage1 = open_image_in_cv(pilimage)
pilimage2 = open_image_in_cv(pilimage, channels_in_output=4)
pilimage3 = open_image_in_cv(pilimage, channels_in_output=2)
pilimage4 = open_image_in_cv(pilimage, channels_in_output=3)

#float images to np.uint8
floatimage = pilimage4.astype(float)
floatimage1 = open_image_in_cv(floatimage)
floatimage2 = open_image_in_cv(floatimage, channels_in_output=4)
floatimage3 = open_image_in_cv(floatimage, channels_in_output=2)
floatimage4 = open_image_in_cv(floatimage, channels_in_output=3)

#filepath
filepath = "c:\\testestestes.png"
pilimage.save(filepath)
filepath1 = open_image_in_cv(filepath, bgr_to_rgb=True)
filepath2 = open_image_in_cv(filepath, channels_in_output=4, bgr_to_rgb=True)
filepath3 = open_image_in_cv(filepath, channels_in_output=2, bgr_to_rgb=True)
filepath4 = open_image_in_cv(filepath, channels_in_output=3, bgr_to_rgb=True)


from a_cv2_imshow_thread import add_imshow_thread_to_cv2
add_imshow_thread_to_cv2()
cv2.imshow_thread(
    [
        base64imgcv,
        base64img2cv,
        linkcv1,
        linkcv2,
        linkcv3,
        linkcv4,
        byteimage1,
        byteimage2,
        byteimage3,
        byteimage4,
        pilimage1,
        pilimage2,
        pilimage3,
        pilimage4,
        floatimage1,
        floatimage2,
        floatimage3,
        floatimage4,
        filepath1,
        filepath2,
        filepath3,
        filepath4,
    ]
)
        Parameters:
            image:Any
                Can be URL, bytes, base64, file path, np.ndarray, PIL
            channels_in_output:Union[int,None]
                None (original image won't be changed)
                2 (GRAY)
                3 (BGR)
                4 (BGRA)
                (default=None)
            bgr_to_rgb:bool=False
                Converts BGRA to RGBA / BGR to RGB
        Returns:
            image:np.ndarray
                (Always as np.uint8)
```