# OpenCV reads image differently based on installation (pip vs conda)

**URL:** <https://forum.opencv.org/t/opencv-reads-image-differently-based-on-installation-pip-vs-conda/1223>\
**Category:** Python\
**Tags:** build, imgcodecs\
**Created:** [January 31, 2021, 5:52am UTC](https://forum.opencv.org/t/opencv-reads-image-differently-based-on-installation-pip-vs-conda/1223 "2021-01-31T05:52:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ashnair1](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/ashnair1/32/805_2.png) [@ashnair1](https://forum.opencv.org/u/ashnair1)\
**Post date:** [January 31, 2021, 5:52am UTC](https://forum.opencv.org/t/opencv-reads-image-differently-based-on-installation-pip-vs-conda/1223/1 "2021-01-31T05:52:28Z")

</div>

Depending on whether opencv was installed via conda or pip, it reads the same image differently. The following is the script and image I used to test this.

### Code

```auto
import cv2
import rasterio as rio
from skimage import io
import numpy as np

def check(path):
    # All images should be in RGB mode
    im1 = rio.open(path)
    im1 = im1.read()
    im1 = im1.transpose(1, 2, 0) # CHW to HWC
    im2 = cv2.imread(path)
    im2 = im2[:,:,::-1] # BGR to RGB
    im3 = io.imread(path)
    

    print(f"Rasterio and OpenCV = {np.all(im1[:,:,0] == im2[:,:,0])}")
    print(f"Rasterio and Skimage = {np.all(im1[:,:,0] == im3[:,:,0])}")

if __name__ == " __main__":
    check("rgb.jpg")

```

### How to reproduce

Create two environments as follows:

```auto
conda create -n s1 -c conda-forge rasterio scikit-image python=3.7
conda activate s1
pip install opencv-python

```

```auto
conda create -n s2 -c conda-forge rasterio scikit-image opencv python=3.7

```

### Link to image [here](https://drive.google.com/file/d/10WaMeePEqlbKjjSotjJNu1gST79emgiO/view?usp=sharing)

### Output

```auto
# For s1 (opencv from pip)
Rasterio and OpenCV = False
Rasterio and Skimage = True

```

```auto
# For s2 (opencv from conda)
Rasterio and OpenCV = True
Rasterio and Skimage = True

```

s1 returns False for the rasterio vs opencv test, whereas s2 returns True for the same.

Why does this happen?

---

<div class="post-metadata">

**Author:** ![laurent.berger](https://avatars.discourse-cdn.com/v4/letter/l/ec9cab/32.png) [@laurent.berger](https://forum.opencv.org/u/laurent.berger)\
**Post date:** [January 31, 2021, 7:26am UTC](https://forum.opencv.org/t/opencv-reads-image-differently-based-on-installation-pip-vs-conda/1223/2 "2021-01-31T07:26:10Z")

</div>

Because it’s not same library used for jpeg

---

<div class="post-metadata">

**Author:** ![ashnair1](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/ashnair1/32/805_2.png) [@ashnair1](https://forum.opencv.org/u/ashnair1)\
**Post date:** [January 31, 2021, 8:49am UTC](https://forum.opencv.org/t/opencv-reads-image-differently-based-on-installation-pip-vs-conda/1223/3 "2021-01-31T08:49:13Z")

</div>

Could you elaborate? What do you mean by not using the same library for jpeg?

---

<div class="post-metadata">

**Author:** ![laurent.berger](https://avatars.discourse-cdn.com/v4/letter/l/ec9cab/32.png) [@laurent.berger](https://forum.opencv.org/u/laurent.berger)\
**Post date:** [January 31, 2021, 1:20pm UTC](https://forum.opencv.org/t/opencv-reads-image-differently-based-on-installation-pip-vs-conda/1223/4 "2021-01-31T13:20:13Z")

</div>

use print(cv.getBuildInformation()) to check lib :

```
  Media I/O:
    ZLib: optimized G:/lib/install/zlib/lib/zlibstatic.lib debug G:/lib/install/zlib/lib/zlibstaticd.lib (ver 1.2.11)
    JPEG: build-libjpeg-turbo (ver 2.0.6-62)
    WEBP: build (ver encoder: 0x020f)
    PNG: optimized G:/lib/install/libpng/lib/libpng16_static.lib debug G:/lib/install/libpng/lib/libpng16_staticd.lib (ver 1.6.36)
    TIFF: build (ver 42 - 4.0.10)
    JPEG 2000: build (ver 2.3.1)
    OpenEXR: build (ver 2.3.0)
    HDR: YES
    SUNRASTER: YES
    PXM: YES
    PFM: YES
  Video I/O:
    DC1394: NO
    FFMPEG: YES (prebuilt binaries)
      avcodec: YES (58.91.100)
      avformat: YES (58.45.100)
      avutil: YES (56.51.100)
      swscale: YES (5.7.100)
      avresample: YES (4.0.0)
    GStreamer: NO
    DirectShow: YES
    Media Foundation: YES
      DXVA: YES
```

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [January 31, 2021, 2:39pm UTC](https://forum.opencv.org/t/opencv-reads-image-differently-based-on-installation-pip-vs-conda/1223/5 "2021-01-31T14:39:40Z")

</div>

you should _never_ expect lossy file formats to compress and decompress to _identical_ results.

---

<div class="post-metadata">

**Author:** ![ashnair1](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/ashnair1/32/805_2.png) [@ashnair1](https://forum.opencv.org/u/ashnair1)\
**Post date:** [January 31, 2021, 6:15pm UTC](https://forum.opencv.org/t/opencv-reads-image-differently-based-on-installation-pip-vs-conda/1223/6 "2021-01-31T18:15:33Z")

</div>

Thanks. That was exactly it. Post 3.3.0.10, opencv-python ships with `libjpeg-turbo` and that’s what you get when you install via `pip`. The conda version ships with `libjpeg`. That was the reason the images were read differently.
