ROI 区域提取和ROI 区域图像叠加
ROI 区域提取
#include <opencv2/opencv.hpp>
int main() {
cv::Mat image = cv::imread("1.jpg");
if (image.empty()) {
std::cerr << "Error: Could not read the image." << std::endl;
return -1;
}
cv::Rect roiRect(100, 50, 200, 150);
cv::Mat roi = image(roiRect);
cv::cvtColor(roi, roi, cv::COLOR_BGR2GRAY);
cv::imshow("Original Image", image);
cv::imshow("ROI (Gray)", roi);
cv::waitKey(0);
return 0;
}
ROI 区域图像叠加
#include <opencv2/opencv.hpp>
int main() {
cv::Mat image = cv::imread("1.jpg");
cv::Mat logo = cv::imread("2.jpg");
if (image.empty() || logo.empty()) {
std::cerr << "Error: Could not read the image(s)." << std::endl;
return -1;
}
cv::Rect roiRect(100, 250, logo.cols, logo.rows);
cv::Mat imageROI = image(roiRect);
logo.copyTo(imageROI);
cv::imshow("Original Image", image);
cv::waitKey(0);
return 0;
}