I have a program that sets up an image to record measurements through user input using the mouse. After showing the image with imshow(), I ask the user if they would like to crop. While waiting for input to the command window, the namedWindow is not responding, and if the user clicks the window before specifying whether or not to crop, the window takes that as the first point to use for cropping.
Is there a way have the command window and namedWindow work in unison?
Constructor for measurment class:
MeasurementClass::MeasurmentClass(){ SetWorkingDirectory(); std::cout << "Before continuing, make sure image files are located in:\n\n " << "\"" + WorkingDirectory + "\"\n" << std::endl; setfilename: SetFileName(); //uncomment after debug SetDate(); Image = cv::imread(XrayFileName, CV_LOAD_IMAGE_COLOR); FinalImage = Image.clone(); if(Image.empty()){ std::cout << "Image failed to Load. Ensure correct image name and file location.\n" << std::endl; goto setfilename; } GetDesktopResolution(); ResizeImageForDisplay(); FinalDisplayImage = DisplayImage.clone(); cv::namedWindow(WindowName, cv::WINDOW_AUTOSIZE); cv::imshow(WindowName, DisplayImage); cv::waitKey(10); PromptForCrop();}
PromptFor Crop()
void MeasurementClass::PromptForCrop(void){ std::cout << "Would you like to crop image? (y/n): "; std::string strCrop; std::getline(std::cin, strCrop); std::cout << std::endl; char Crop = strCrop[0]; switch(Crop){ case 'y': case '\0': CropImage(); default: break; } }
Bonus
It has recently been brought to my attention that goto statements are terrible practice. In this situation, what is a good alternative to the goto statement.
goto. They make the code difficult to read and error prone. Here you can use something like:do { ... } while(!Image.empty())- Miki