System Information
OpenCV version: 4.9.0
Operating System / Platform: Windows 10 x64
Compiler & compiler version: MinGW GCC 7.3.0
OpenCV python version: 4.9.0.80
Python version: 3.9.6
Issue
I try to show image/stream video to window using openCV but this window freezes after exactly 4 updates. No matter what language I use: cpp/python/go, result always is the same. This problem appears on 2 different windows machines.
Result of code execution:
Cpp code:
#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
std::string image_path = samples::findFile("pic.png");
cv::Mat image = cv::imread(image_path, cv::IMREAD_COLOR);
for(;;) {
cout << "x\n";
cv::imshow("Output Window", image);
cv::waitKey(1);
}
return 0;
}
Python code:
import cv2
video = cv2.VideoCapture(0)
address = "https://192.168.0.23:8080/video"
video.open(address)
while(1):
print("x\n")
check, frame = video.read()
cv2.imshow("zcx", frame)
k = cv2.waitKey(1) & 0xFF
if k == 27:
break
Before that I had this build error (here openCV has another version, but I have this error on any version):
C:\opencv\opencv-4.8.1\modules\core\src\parallel.cpp: In function 'int cv::getThreadNum()':
C:\opencv\opencv-4.8.1\modules\core\src\parallel.cpp:804:25: error: invalid cast from type 'pthread_t' {aka 'ptw32_handle_t'} to type 'void*'
804 | return (int)(size_t)(void*)pthread_self(); // no zero-based indexing
| ^~~~~~~~~~~~~~~~~~~~~
mingw32-make[2]: *** [modules\core\CMakeFiles\opencv_core.dir\build.make:1003: modules/core/CMakeFiles/opencv_core.dir/src/parallel.cpp.obj] Error 1
mingw32-make[1]: *** [CMakeFiles\Makefile2:3854: modules/core/CMakeFiles/opencv_core.dir/all] Error 2
mingw32-make: *** [Makefile:165: all] Error 2
I fixed this error by this steps:
- change
(int)(size_t)(void*)pthread_self();
on line 804 to(int)(size_t)pthread_self().p;
in open parallel.cpp - changed
posix_thread(0)
on line 218 toposix_thread()
in parallel_impl.cpp