# ROI selection cv2.selectROI not working in Google Colab

**URL:** <https://forum.opencv.org/t/roi-selection-cv2-selectroi-not-working-in-google-colab/11228>\
**Category:** Python\
**Tags:** programming, colab\
**Created:** [December 6, 2022, 1:48pm UTC](https://forum.opencv.org/t/roi-selection-cv2-selectroi-not-working-in-google-colab/11228 "2022-12-06T13:48:46Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![MMML](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/mmml/32/6682_2.png) [@MMML](https://forum.opencv.org/u/MMML)\
**Post date:** [December 6, 2022, 1:48pm UTC](https://forum.opencv.org/t/roi-selection-cv2-selectroi-not-working-in-google-colab/11228/1 "2022-12-06T13:48:46Z")

</div>

I’m learning opencv for object detection and trying to do all the coding using google colab. And so far it has been working well: I can mount the gdrive and upload file and read the video file just fine.

The selecting ROI by passing video frame into cv2.selectROI() crashed the Colab. The runtime log complained about a plugin xcb not initialising. Further reading reveals the plug in require to be run on local machine, so I wonder if there is a way to run cv2.selectROI or equivalent on colab?

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [December 7, 2022, 8:45am UTC](https://forum.opencv.org/t/roi-selection-cv2-selectroi-not-working-in-google-colab/11228/2 "2022-12-07T08:45:55Z")

</div>

> [@MMML](#):
>
> crashed the Colab

that’s expected. you cannot use ANY opencv gui functions (imshow, waitkey, mouse, trackbars) on colab, it is _remote_ server.

---

<div class="post-metadata">

**Author:** ![MMML](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/mmml/32/6682_2.png) [@MMML](https://forum.opencv.org/u/MMML)\
**Post date:** [December 7, 2022, 12:42pm UTC](https://forum.opencv.org/t/roi-selection-cv2-selectroi-not-working-in-google-colab/11228/3 "2022-12-07T12:42:50Z")

</div>

Sorry I’m very new to all these.  
IS there any work around to this? for example in this case I want to label a ROI in a video using openCV. Or my option really is start using pycharm?

---

<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:** [December 7, 2022, 10:24pm UTC](https://forum.opencv.org/t/roi-selection-cv2-selectroi-not-working-in-google-colab/11228/4 "2022-12-07T22:24:25Z")

</div>

> [@MMML](#):
>
> pycharm

no. you misunderstand.

pycharm has NOTHING to do with this.

your mistake is expecting GUI from a server on the internet.

run the stuff locally. this DOES NOT REQUIRE PYCHARM, okay? it just requires python and opencv, on your local machine.

pycharm is not equal to python, nor is it equal to having python on your own machine.

---

<div class="post-metadata">

**Author:** ![MMML](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/mmml/32/6682_2.png) [@MMML](https://forum.opencv.org/u/MMML)\
**Post date:** [December 13, 2022, 1:42pm UTC](https://forum.opencv.org/t/roi-selection-cv2-selectroi-not-working-in-google-colab/11228/5 "2022-12-13T13:42:12Z")

</div>

my bad, when I say pycharm I mean to run python on my local machine, my IDE is pycharm…you are absolutely right though, run it on my local machine would be the easiest fix.

I read around on StackOverflow, and found out the same problem with cv2.imshow(), and there seems to have a workaround using

`from google.colab.patches import cv2_imshow`  
so I wonder if there is a workaround like that for roi selection? I know this is like taking the long road, but for the sake of learning…

---

<div class="post-metadata">

**Author:** ![thangngoc89](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/thangngoc89/32/6715_2.png) [@thangngoc89](https://forum.opencv.org/u/thangngoc89)\
**Post date:** [December 13, 2022, 2:34pm UTC](https://forum.opencv.org/t/roi-selection-cv2-selectroi-not-working-in-google-colab/11228/6 "2022-12-13T14:34:01Z")

</div>

> [@MMML](#):
>
> cv2.selectROI

If you really don’t want to run python locally and prefer notebook-like GUI, you can read this article about selecting ROI with jupyter (since Google Colab is a hosted Jupyter Lab instance)

> **[How to select ROI in Jupyter Notebook ?](https://medium.com/@khandelwalprateek01/how-to-select-roi-in-jupyter-notebook-309fe5185a54)**
>
> Introduction

---

<div class="post-metadata">

**Author:** ![MMML](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/mmml/32/6682_2.png) [@MMML](https://forum.opencv.org/u/MMML)\
**Post date:** [December 13, 2022, 10:00pm UTC](https://forum.opencv.org/t/roi-selection-cv2-selectroi-not-working-in-google-colab/11228/7 "2022-12-13T22:00:51Z")

</div>

Thank you so much man!  
This might just be the thing I’m looking for. I’m a dummy so before I never paid attention to the difference between colab/notebook and a local IDE… Great things to learn.
