# Opencv-python trackbar crash when I slide

**URL:** <https://forum.opencv.org/t/opencv-python-trackbar-crash-when-i-slide/10239>\
**Category:** Python\
**Tags:** highgui, apple\
**Created:** [September 18, 2022, 9:32am UTC](https://forum.opencv.org/t/opencv-python-trackbar-crash-when-i-slide/10239 "2022-09-18T09:32:23Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![xwwwb](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/xwwwb/32/6077_2.png) [@xwwwb](https://forum.opencv.org/u/xwwwb)\
**Post date:** [September 18, 2022, 9:32am UTC](https://forum.opencv.org/t/opencv-python-trackbar-crash-when-i-slide/10239/1 "2022-09-18T09:32:23Z")

</div>

Hi everyone,  
I created a palette using trackbar,  
When I slide, the window closes,

error message:

```auto
[1] 87735 segmentation fault python seven_trackbar.py

```

this is my code:

```auto
import cv2
import numpy as np

def callback(x):
    print(x)

cv2.namedWindow('trackbar', cv2.WINDOW_NORMAL)

cv2.createTrackbar('R', 'trackbar', 0, 255, callback)
cv2.createTrackbar('G', 'trackbar', 0, 255, callback)
cv2.createTrackbar('B', 'trackbar', 0, 255, callback)

img = np.zeros((480, 460, 3), np.uint8)

while True:
    r = cv2.getTrackbarPos('R', 'trackbar')
    g = cv2.getTrackbarPos('G', 'trackbar')
    b = cv2.getTrackbarPos('B', 'trackbar')
    img[:] = [b, g, r]
    cv2.imshow('trackbar', img)

    key = cv2.waitKey(0)
    if key & 0xff == ord('q'):
        break

cv2.destroyAllWindows()

```

```auto
Macbook air M1
Python 3.10.4 
opencv-python 4.6.0.66

```

Does anyone know how to solve it 😭😭

---

<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:** [September 18, 2022, 10:20am UTC](https://forum.opencv.org/t/opencv-python-trackbar-crash-when-i-slide/10239/2 "2022-09-18T10:20:38Z")

</div>

please tell us, which gui toolkit is used here  
(`print(cv2.getBuildInformation())`)

---

<div class="post-metadata">

**Author:** ![matti.vuori](https://avatars.discourse-cdn.com/v4/letter/m/e79b87/32.png) [@matti.vuori](https://forum.opencv.org/u/matti.vuori)\
**Post date:** [September 18, 2022, 10:23am UTC](https://forum.opencv.org/t/opencv-python-trackbar-crash-when-i-slide/10239/3 "2022-09-18T10:23:07Z")

</div>

First you obviously need to debug your code and find out the line and expression that segfaults.

It may not even have anything to do with sliding.

---

<div class="post-metadata">

**Author:** ![xwwwb](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/xwwwb/32/6077_2.png) [@xwwwb](https://forum.opencv.org/u/xwwwb)\
**Post date:** [September 18, 2022, 10:50am UTC](https://forum.opencv.org/t/opencv-python-trackbar-crash-when-i-slide/10239/4 "2022-09-18T10:50:19Z")

</div>

```auto
General configuration for OpenCV 4.6.0 =====================================
  Version control: 4.6.0

  Platform:
    Timestamp: 2022-06-07T10:22:17Z
    Host: Darwin 20.2.0 arm64
    CMake: 3.22.3
    CMake generator: Unix Makefiles
    CMake build tool: /usr/bin/make
    Configuration: Release

  CPU/HW features:
    Baseline: NEON FP16

  C/C++:
    Built as dynamic libs?: NO
    C++ standard: 11
    C++ Compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ (ver 12.0.5.12050022)
    C++ flags (Release): -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Qunused-arguments -Wno-semicolon-before-method-body -ffunction-sections -fdata-sections -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG -DNDEBUG
    C++ flags (Debug): -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Qunused-arguments -Wno-semicolon-before-method-body -ffunction-sections -fdata-sections -fvisibility=hidden -fvisibility-inlines-hidden -g -O0 -DDEBUG -D_DEBUG
    C Compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
    C flags (Release): -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Qunused-arguments -Wno-semicolon-before-method-body -ffunction-sections -fdata-sections -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG -DNDEBUG
    C flags (Debug): -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Qunused-arguments -Wno-semicolon-before-method-body -ffunction-sections -fdata-sections -fvisibility=hidden -fvisibility-inlines-hidden -g -O0 -DDEBUG -D_DEBUG
    Linker flags (Release): -Wl,-dead_strip  
    Linker flags (Debug): -Wl,-dead_strip  
    ccache: YES
    Precompiled headers: NO
    Extra dependencies: -framework OpenCL /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/System/Library/Frameworks/Accelerate.framework -lm -ldl -framework Cocoa -framework AppKit
    3rdparty dependencies: libprotobuf ade ittnotify libjpeg-turbo libwebp libpng libtiff libopenjp2 IlmImf zlib quirc tegra_hal

  OpenCV modules:
    To be built: calib3d core dnn features2d flann gapi highgui imgcodecs imgproc ml objdetect photo python3 stitching video videoio
    Disabled: world
    Disabled by dependency: -
    Unavailable: java python2 ts
    Applications: -
    Documentation: NO
    Non-free algorithms: NO

  GUI: COCOA
    Cocoa: YES
    VTK support: NO

  Media I/O: 
    ZLib: build (ver 1.2.12)
    JPEG: build-libjpeg-turbo (ver 2.1.2-62)
    WEBP: build (ver encoder: 0x020f)
    PNG: build (ver 1.6.37)
    TIFF: build (ver 42 - 4.2.0)
    JPEG 2000: build (ver 2.4.0)
    OpenEXR: build (ver 2.3.0)
    HDR: YES
    SUNRASTER: YES
    PXM: YES
    PFM: YES

  Video I/O:
    DC1394: NO
    FFMPEG: YES
      avcodec: YES (58.134.100)
      avformat: YES (58.76.100)
      avutil: YES (56.70.100)
      swscale: YES (5.9.100)
      avresample: YES (4.0.0)
    GStreamer: NO
    AVFoundation: YES

  Parallel framework: GCD

  Trace: YES (with Intel ITT)

  Other third-party libraries:
    Lapack: YES (/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/System/Library/Frameworks/Accelerate.framework -lm -ldl)
    Eigen: NO
    Custom HAL: YES (carotene (ver 0.0.1))
    Protobuf: build (3.19.1)

  OpenCL: YES (no extra features)
    Include path: NO
    Link libraries: -framework OpenCL

  Python 3:
    Interpreter: /Users/xperience/.pyenv/versions/3.7.10/bin/python3.7 (ver 3.7.10)
    Libraries: /Users/xperience/.pyenv/versions/3.7.10/lib/libpython3.7m.a (ver 3.7.10)
    numpy: /Users/xperience/.pyenv/versions/3.7.10/lib/python3.7/site-packages/numpy/core/include (ver 1.21.0)
    install path: python/cv2/python-3

  Python (for build): /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7

  Java:                          
    ant: NO
    JNI: NO
    Java wrappers: NO
    Java tests: NO

  Install to: /Users/xperience/actions-runner/_work/opencv-python/opencv-python/_skbuild/macosx-11.0-arm64-3.7/cmake-install

```

I use pip to install

---

<div class="post-metadata">

**Author:** ![xwwwb](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/xwwwb/32/6077_2.png) [@xwwwb](https://forum.opencv.org/u/xwwwb)\
**Post date:** [September 18, 2022, 10:52am UTC](https://forum.opencv.org/t/opencv-python-trackbar-crash-when-i-slide/10239/5 "2022-09-18T10:52:22Z")

</div>

I use single step debugging  
When the code runs to  
` key=cv2. waitKey (0)`  
it will crash

---

<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:** [September 18, 2022, 12:45pm UTC](https://forum.opencv.org/t/opencv-python-trackbar-crash-when-i-slide/10239/6 "2022-09-18T12:45:54Z")

</div>

> [@xwwwb](#):
>
> `Darwin `

yeah, highgui trackbars are buggy on apple

---

<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:** [September 18, 2022, 1:04pm UTC](https://forum.opencv.org/t/opencv-python-trackbar-crash-when-i-slide/10239/7 "2022-09-18T13:04:42Z")

</div>

let the devs know, [and raise an issue](https://github.com/opencv/opencv/issues/new/choose)

---

<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:** [September 18, 2022, 1:08pm UTC](https://forum.opencv.org/t/opencv-python-trackbar-crash-when-i-slide/10239/8 "2022-09-18T13:08:54Z")

</div>

better yet, **check** for existing issues.

> **[Issues · opencv/opencv](https://github.com/opencv/opencv/issues?q=label%3A%22category%3A%2Bhighgui-gui%22%2Btrackbar%2B)**
>
> Open Source Computer Vision Library. Contribute to opencv/opencv development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![kosFoo](https://avatars.discourse-cdn.com/v4/letter/k/e9a140/32.png) [@kosFoo](https://forum.opencv.org/u/kosFoo)\
**Post date:** [December 4, 2022, 10:16am UTC](https://forum.opencv.org/t/opencv-python-trackbar-crash-when-i-slide/10239/9 "2022-12-04T10:16:23Z")

</div>

This macOs ARM related issue has been solved with the rolling built packages:

Use pip install opencv-contrib-python-rolling for example. (v 5.0.0.20221015 at the time of writing).

Issue: [OpenCV Trackbar Crash on ARM Mac · Issue #22561 · opencv/opencv · GitHub](https://github.com/opencv/opencv/issues/22561)
