opencv笔记9-图像像素的逻辑操作

图像像素的逻辑操作

#include
#include

using namespace std;
using namespace cv;

//图像像素的逻辑操作
void bitwirte_demo(cv::Mat& image)
{
	Mat m1 = Mat::zeros(Size(256, 256), CV_8UC3);
	Mat m2 = Mat::zeros(Size(256, 256), CV_8UC3);

	//矩形绘制
	rectangle(m1, Rect(100, 100, 80, 80), Scalar(255, 255, 0), -1, LINE_8, 0);
	rectangle(m2, Rect(160, 160, 80, 80), Scalar(0, 255, 0), -1, LINE_8, 0);
	imshow("m1", m1);
	imshow("m2", m2);
	Mat dst;
	bitwise_and(m1, m2, dst);
	imshow("像素位操作1", dst);
	bitwise_or(m1, m2, dst);
	imshow("像素位操作2", dst);
	bitwise_not(image, dst);
	imshow("像素位操作3", dst);
	bitwise_xor(m1, m2, dst);
	imshow("像素位操作4", dst);
}

int main()
{
	string path = "C:\\Users\\四明\\Pictures\\QQ图片20200608155343.jpg";
	Mat img = imread(path);
	if (img.empty())
	{
		cout << "图片加载失败!" << endl;
		return -1;
	}
	namedWindow("image", WINDOW_FREERATIO);
	imshow("image", img);
	bitwirte_demo(img);
	waitKey(0);
	destroyAllWindows();
	return 0;
}

你可能感兴趣的:(opencv笔记,笔记,c++,opencv)