Reputation: 29
I am running QT (5.15.2) on a Raspberry Pi (4B, Raspbian Bullseye 11) and using OpenCV (4.5.1) to do some image processing. I have a main window with 2 buttons in which one starts as greyed out as the first step must be completed before the second. I use the hide() QT function to hide the main window and pop up some gui elements using OpenCV. Once the OpenCV elements are finished and destroyed, I use show() to bring back the main window and ungrey the second button via setEnabled(true). This is where the problem occurs, as but buttons become unpressable on the screen, ie I cannot press the button on the touchscreen I am using.
Through testing I have found that when the loop that controls the OpenCV elements is allowed to end via the time expiring, then the problem does not occur. When the OpenCV elements are manually closed via sliding the "Set" slider from 0 to 1, then the problem occurs. The problem does not occur when using any of the other sliders
The buttons are still active however, as when I plug a keyboard in I can still operate the buttons and the code runs as usual, but I cannot press them using my finger or a mouse. Unfortunately having a keyboard to operate it isn't going to work for my use case.
The code for the loop that controls the OpenCV elements is:
void MainWindow::on_Button1_clicked()
hide();
//Code to load image is here, but is just the basic way of image loading with OpenCV
//Code to create the two OpenCV windows needed inside the loop goes here
time(&iTime);
while(OnOff == 0 && difftime(cTime,iTime) < 5){
createTrackbar(track_val, ControlPanel,&thresh_val,thresh_max_val); //binary gray value
createTrackbar(track_OnOff, ControlPanel,&OnOff,1); //video window on and off
createTrackbar(X_top_left, ControlPanel,&X,638); //bounding box top left X
createTrackbar(Y_top_left, ControlPanel,&Y,478); //bounding box top left Y
createTrackbar(X_size, ControlPanel,&Width,640); //bounding box width
createTrackbar(Y_size, ControlPanel,&Height,480); //bounding box height
createTrackbar(Max_Rad, ControlPanel,&max_rad,max_circ_rad); //Circle Size
imshow(ImageWin, img);
waitKey(1);
time(&cTime);
}
destroyAllWindows();
show();
}
I have uploaded all the code as a minimum reproducible example here.
Thanks for any help.
Upvotes: 1
Views: 118
Reputation: 29
I was not able to find the cause of the issue however I was able to get around the issue. Using Yunus' advice, I removed the OpenCV gui components.
I used this code to create a method that opened the webcam so I could use OpenCV to process the image in the manner I needed.
So lesson learned, don't mix two different gui generators.
Upvotes: 1