compile opencv program
// Step 1: Include necessary header files
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
int main() {
// Step 2: Read an image from file
Mat image = imread("path/to/your/image.jpg");
// Step 3: Check if the image was successfully loaded
if (image.empty()) {
return -1;
}
// Step 4: Create a window to display the image
namedWindow("Display Image", WINDOW_AUTOSIZE);
// Step 5: Show the image in the created window
imshow("Display Image", image);
// Step 6: Wait for a key press
waitKey(0);
// Step 7: Close the created window
destroyWindow("Display Image");
// Step 8: Return from the program
return 0;
}
Ensure that you have OpenCV installed and configured correctly in your development environment. Update the file path in the imread
function with the actual path to your image file. Compile the program using a C++ compiler with OpenCV support.