Cv::imshow() error in cv::hal_AVX2::v_load_deinterleave

Please help me look at this problem:

Thread 1 received signal SIGSEGV, Segmentation fault.
0x000000000103f737 in cv::hal_AVX2::v_load_deinterleave (ptr=0x4ca24c0 “”, a=…, b=…, c=…) at C:/workspace/opencv-4.7.0/modules/core/include/opencv2/core/hal/intrin_avx.hpp:2447
2447 a = v_uint8x32(b0);

I got an error trying to display an image using imShow()

main.cpp:

#include <iostream>
#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"

using namespace std;
using namespace cv;

int main(int argc, char *argv[]) {
    Mat img = Mat::zeros(500, 500, CV_8UC3);
    Point point_1(10, 100);
    Point point_2(10, 200);
    const Scalar white = Scalar(255);
    const Scalar black = Scalar(0);
    line(img, point_1, point_2, white);

    namedWindow("img");
    imshow("img", img);

    waitKey();
    return 0;
}

General configuration for OpenCV 4.7.0:

--   Version control:               unknown
--
--   Platform:
--     Timestamp:                   2023-05-16T07:34:14Z
--     Host:                        Windows 10.0.19044 AMD64
--     CMake:                       3.25.3
--     CMake generator:             MinGW Makefiles
--     CMake build tool:            C:/software/MinGW/mingw64-8.1.0-posix-seh/bin/mingw32-make.exe
--     Configuration:               DEBUG
--
--   CPU/HW features:
--     Baseline:                    SSE SSE2 SSE3
--       requested:                 SSE3
--     Dispatched code generation:  SSE4_1 SSE4_2 FP16 AVX AVX2
--       requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
--       SSE4_1 (13 files):         + SSSE3 SSE4_1
--       SSE4_2 (1 files):          + SSSE3 SSE4_1 POPCNT SSE4_2
--       FP16 (0 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
--       AVX (3 files):             + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
--       AVX2 (24 files):           + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
--
--   C/C++:
--     Built as dynamic libs?:      YES
--     C++ standard:                11
--     C++ Compiler:                C:/software/MinGW/mingw64-8.1.0-posix-seh/bin/c++.exe  (ver 8.1.0)
--     C++ flags (Release):         -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG -g1
--     C++ flags (Debug):           -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG
--     C Compiler:                  C:/software/MinGW/mingw64-8.1.0-posix-seh/bin/gcc.exe
--     C flags (Release):           -fsigned-char -W -Wall -Wreturn-type -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -O3 -DNDEBUG  -DNDEBUG -g1
--     C flags (Debug):             -fsigned-char -W -Wall -Wreturn-type -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -g  -O0 -DDEBUG -D_DEBUG
--     Linker flags (Release):      -Wl,--gc-sections  
--     Linker flags (Debug):        -Wl,--gc-sections
--     ccache:                      NO
--     Precompiled headers:         NO
--     Extra dependencies:          pthread
--     3rdparty dependencies:
--
--   OpenCV modules:
--     To be built:                 core highgui imgproc
--     Disabled:                    calib3d dnn features2d flann gapi imgcodecs ml objdetect photo stitching video videoio world
--     Disabled by dependency:      -
--     Unavailable:                 java python2 python3 ts
--     Applications:                -
--     Documentation:               NO
--     Non-free algorithms:         NO
--
--   Windows RT support:            NO
--
--   GUI:                           WIN32UI
--     Win32 UI:                    YES
--     VTK support:                 NO
--
--   Media I/O:
--     ZLib:                        build (ver 1.2.13)
--     JPEG:                        build-libjpeg-turbo (ver 2.1.3-62)
--       SIMD Support Request:      YES
--       SIMD Support:              NO
--     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:                      NO
--       avcodec:                   NO
--       avformat:                  NO
--       avutil:                    NO
--       swscale:                   NO
--       avresample:                NO
--     GStreamer:                   NO
--     DirectShow:                  YES
--
--   Parallel framework:            pthreads
--
--   Trace:                         YES (built-in)
--
--   Other third-party libraries:
--     Lapack:                      NO
--     Eigen:                       NO
--     Custom HAL:                  NO
--     Protobuf:                    build (3.19.1)
--
--   OpenCL:                        YES (NVD3D11)
--     Include path:                C:/workspace/opencv-4.7.0/3rdparty/include/opencl/1.2
--     Link libraries:              Dynamic load
--
--   Python (for build):            NO
--   Java:
--     ant:                         NO
--     JNI:                         NO
--     Java wrappers:               NO
--     Java tests:                  NO
--
--   Install to:                    C:/workspace/opencv-4.7.0/build
-- -----------------------------------------------------------------
--
-- Configuring done
-- Generating done

There is no problem with your code in my configuration. I can set a breakpoint and there is no exception :

|>|opencv_imgproc470d.dll!cv::hal_AVX2::v_load_deinterleave(const unsigned char * ptr, cv::hal_AVX2::v_uint8x32 & a, cv::hal_AVX2::v_uint8x32 & b, cv::hal_AVX2::v_uint8x32 & c) Line 2447|C++|
|| |opencv_imgproc470d.dll!cv::hal::opt_AVX2::`anonymous namespace'::RGB2RGB<unsigned char>::operator()(const unsigned char * src, unsigned char * dst, int n) Line 139|C++|
| |opencv_imgproc470d.dll!cv::hal::opt_AVX2::`anonymous namespace'::CvtColorLoop_Invoker<cv::hal::opt_AVX2::`anonymous namespace'::RGB2RGB<unsigned char>>::operator()(const cv::Range & range) Line 147|C++|
| |opencv_core470d.dll!cv::`anonymous namespace'::ParallelLoopBodyWrapper::operator()(const cv::Range & sr) Line 354|C++|
| |opencv_core470d.dll!cv::`anonymous namespace'::ProxyLoopBody::operator()(int i) Line 444|C++|
| |[External Code]||
| |opencv_core470d.dll!cv::parallel_for_impl(const cv::Range & range, const cv::ParallelLoopBody & body, double nstripes) Line 600|C++|
| |opencv_core470d.dll!cv::parallel_for_(const cv::Range & range, const cv::ParallelLoopBody & body, double nstripes) Line 523|C++|
| |opencv_imgproc470d.dll!cv::hal::opt_AVX2::`anonymous namespace'::CvtColorLoop<cv::hal::opt_AVX2::`anonymous namespace'::RGB2RGB<unsigned char>>(const unsigned char * src_data, unsigned __int64 src_step, unsigned char * dst_data, unsigned __int64 dst_step, int width, int height, const cv::hal::opt_AVX2::`anonymous-namespace'::RGB2RGB<unsigned char> & cvt) Line 166|C++|
| |opencv_imgproc470d.dll!cv::hal::opt_AVX2::cvtBGRtoBGR(const unsigned char * src_data, unsigned __int64 src_step, unsigned char * dst_data, unsigned __int64 dst_step, int width, int height, int depth, int scn, int dcn, bool swapBlue) Line 1101|C++|
| |opencv_imgproc470d.dll!cv::hal::cvtBGRtoBGR(const unsigned char * src_data, unsigned __int64 src_step, unsigned char * dst_data, unsigned __int64 dst_step, int width, int height, int depth, int scn, int dcn, bool swapBlue) Line 236|C++|
| |opencv_imgproc470d.dll!cv::cvtColorBGR2BGR(const cv::debug_build_guard::_InputArray & _src, const cv::debug_build_guard::_OutputArray & _dst, int dcn, bool swapb) Line 554|C++|
| |opencv_imgproc470d.dll!cv::cvtColor(const cv::debug_build_guard::_InputArray & _src, const cv::debug_build_guard::_OutputArray & _dst, int code, int dcn) Line 199|C++|
| |opencv_highgui470d.dll!convertToShow(const cv::Mat & src, cv::Mat & dst, bool toRGB) Line 176|C++|
| |opencv_highgui470d.dll!showImage_(CvWindow & window, const cv::Mat & image) Line 1448|C++|
| |opencv_highgui470d.dll!cv::impl::Win32UIWindow::imshow(const cv::debug_build_guard::_InputArray & image) Line 2758|C++|
| |opencv_highgui470d.dll!cv::imshow(const std::string & winname, const cv::debug_build_guard::_InputArray & _img) Line 987|C++|

In your code as your image type is CV_8UC3 is better to set :

        const Scalar white = Scalar(255, 255, 255);
        const Scalar black = Scalar(0, 0, 0);

I don’t use mingw a s compiler but vs2022

Thanks for your advice.
I’m trying something else