#  How to calculate disparity, using imgL and imgR in the CMYK system?

**URL:** <https://forum.opencv.org/t/how-to-calculate-disparity-using-imgl-and-imgr-in-the-cmyk-system/12551>\
**Category:** Python\
**Tags:** cvtcolor, color, stereo\
**Created:** [March 27, 2023, 10:44pm UTC](https://forum.opencv.org/t/how-to-calculate-disparity-using-imgl-and-imgr-in-the-cmyk-system/12551 "2023-03-27T22:44:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![iuri](https://avatars.discourse-cdn.com/v4/letter/i/ac8455/32.png) [@iuri](https://forum.opencv.org/u/iuri)\
**Post date:** [March 27, 2023, 10:44pm UTC](https://forum.opencv.org/t/how-to-calculate-disparity-using-imgl-and-imgr-in-the-cmyk-system/12551/1 "2023-03-27T22:44:58Z")

</div>

Reading image as RGB and converting them to CMYK resulted in a better color definition to identify markers attached to an actuator. As you can see them in magenta, in the CMYK image attached.

Now, they must be sterilized to calculate disparity, as in:

```auto
stereo = cv.StereoBM_create(numDisparities=16, blockSize=15)
disparity = stereo.compute(CMYK_L, CMYK_R)

```

However, the following error occurs:

```auto
error: OpenCV(4.7.0) /io/opencv/modules/calib3d/src/stereobm.cpp:1173: error: (-210:Unsupported format or combination of formats) Both input images must have CV_8UC1 in function ‘compute’

```

I assumed the error’s because CMYK has a fourth dimension (i.e. K), causing calculations to break.

How can images be converted from CMYK to grayscale directly? (so that I could reuse stereo.compute()

Should I use another color system? or even better, does stereo.compute() support CMYK system?

Converting them back to RGB is not am option/solution. Because markers get lost when the image is converted from RGB to grayscale.

Markers get similar gray as the scenario, making it hard, to any openCV lib or segmentation algorithm such as Cany, to track marker’s coordinates (x,y) accurately.

Do I need to convert them to another system? which one?

![Screen Shot 2023-03-25 at 11.08.44 PM](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/0/04b983e6ca1217c9907990b9717820589eee7464.png)

```auto
error: OpenCV(4.7.0) /io/opencv/modules/calib3d/src/stereobm.cpp:1173: error: (-210:Unsupported format or combination of formats) Both input images must have CV_8UC1 in function ‘compute’

```

---

<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:** [March 28, 2023, 8:28am UTC](https://forum.opencv.org/t/how-to-calculate-disparity-using-imgl-and-imgr-in-the-cmyk-system/12551/2 "2023-03-28T08:28:33Z")

</div>

Hi  
Have you try to use stereo compute on gray image and get disparity map inside your marker?  
May be you can convert you best image in gray scale to get visible marker using cvtColor with a wrong colorspace

If it does not work may be you can use [triangulatePoints](https://docs.opencv.org/5.x/da/d35/group ____ 3d.html#gad3fc9a0c82b08df034234979960b778c)?
