当前位置:网站首页>Opencv learning notes -day10 logical operation of image pixels (usage of rectangle function and rect function and bit related operation in openCV)
Opencv learning notes -day10 logical operation of image pixels (usage of rectangle function and rect function and bit related operation in openCV)
2022-06-30 08:47:00 【Chasing foot dream】
OpenCV Learning notes
day10- Logical operation of image pixels
1. Draw a rectangular
function
Function is used to draw a rectangle ( box ) Of , Usually used in the marking of pictures
// Definition 1
CV_EXPORTS_W void rectangle(InputOutputArray img, Point pt1, Point pt2,
const Scalar& color, int thickness = 1,
int lineType = LINE_8, int shift = 0);
Parameters | explain |
---|---|
img | The processed image |
pt1 | Draw the coordinates of the upper left point of the rectangle |
pt2 | Draw the coordinates of the lower right point of the rectangle |
color | Color Scalar(255,255,0) |
thickness | Line width of rectangular box See in detail #FILLED |
lineType | Linetype Default LINE_8, See in detail #LineTypes |
shift | The number of decimal places in the coordinates of the shift point |
example 1rectangle(img2, Point(j,i), Point(j + img4.cols, i + img4.rows), Scalar(255, 255, 0), 2, 8);
// Definition 2
CV_EXPORTS void rectangle(CV_IN_OUT Mat& img, Rect rec,
const Scalar& color, int thickness = 1,int lineType = LINE_8,
int shift = 0);
Parameter description
1.
Parameters | explain |
---|---|
img | The processed image |
rec | Rect() function |
color | Color Scalar(255,255,0) |
thickness | Line width of rectangular box |
lineType | Linetype Default LINE_8, See in detail #FILLED |
shift | The number of decimal places in the coordinates of the shift point |
Rect()(int x, int y, int width, int height);
Parameter meaning :
Rect( top left corner x coordinate , top left corner y coordinate , The width of the rectangle , The height of the rectangle )
example 2
rectangle(m1,Rect(100,100,80,80),Scalar(255,255,0),-1,LINE_8,0);
example 3
Rect(100,100,80,80);// Top left coordinates x,y(100,100)
//size 80*80
Add :
// If you create a Rect object rect(100, 50, 50, 100), that rect There will be the following functions :
rect.area(); // return rect The area of 5000
rect.size(); // return rect The size of the [50 × 100]
rect.tl(); // return rect The coordinates of the upper left vertex of [100, 50]
rect.br(); // return rect The coordinates of the lower right vertex of [150, 150]
rect.width(); // return rect Width 50
rect.height(); // return rect Height 100
rect.contains(Point(x, y)); // Returns a boolean variable , Judge rect Does it include Point(x, y) spot
// You can also find the intersection and union of two rectangles
rect = rect1 & rect2;
rect = rect1 | rect2;
// You can also pan and zoom the rectangle
rect = rect + Point(-100, 100); // translation , That is, the top left vertex x coordinate -100,y coordinate +100
rect = rect + Size(-100, 100); // The zoom , Top left vertex unchanged , Width -100, Height +100
// You can also compare rectangles , Returns a boolean variable
rect1 == rect2;
rect1 != rect2;
2. Bit operation
function
bitwise_and(m1, m2, dst);// And
bitwise_or(m1, m2, dst);// or
bitwise_not(m1,dst);// Not Reverse operation
bitwise_xor(m1,m2,dst);// Exclusive or
Code
quickopencv.h
#pragma once
#include <opencv2\highgui.hpp>
#include <opencv2\imgproc.hpp>
using namespace cv;
// Defining classes
class QuickDemo{
public:
void colorSpace_Demo(Mat &image);// Color space conversion function 2021-12-24
void mat_creation_demo(Mat &image);//Mat Object and creation 2021-12-27
void pixel_vist_Demo(Mat &image);// Read and write operation of image pixels 2022-1-3
void operators_demo(Mat &image);// Arithmetic operation of image pixels 2022-1-4
void tracking_bar_demo(Mat &image);// Scroll bar operation demonstration 2022-1-7
void key_demo(Mat &image);// Keyboard response operation 2022-1-12
void color_style_demo(Mat &image);//OpenCV With color table operation 2022-1-12
void bitwise_demo(Mat &image);// Bit operation ( Logical operation )2022-1-17
};
QuickDemo.cpp
#include <opencv2\highgui.hpp>
#include <opencv2\imgproc.hpp>
#include<quickopencv.h>
#include <iostream>
void QuickDemo::bitwise_demo(Mat &image)
{
// Draw a rectangular
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(150, 150, 80, 80), Scalar(0, 255, 255), -1, LINE_8, 0);
imshow("m1", m1);// Show results 1
imshow("m2", m2);// Show results 2
// Bit operation
Mat dst;
//bitwise_and(m1, m2, dst);// And
// Show results 3
//bitwise_or(m1, m2, dst);// or
// Show results 4
//bitwise_not(m1,dst);// Not Reverse operation
// Show results 5
bitwise_xor(m1,m2,dst);// Exclusive or
// Show results 6
imshow(" Pixel bit operation ", dst);
}
OpencvTest.cpp
#include <iostream>
#include <opencv2\highgui.hpp>
#include <opencv2\imgproc.hpp>
#include<quickopencv.h>
using namespace cv;
using namespace std;
int main()
{
QuickDemo qd;
qd.bitwise_demo(scr);
waitKey(0);
return 0;
}
According to the effect
Show results 1
Show results 2
Show results 3
Show results 4
Show results 5
Show results 6
边栏推荐
- CUDA implements matrix replication
- 【付费推广】常见问题合集,推荐榜单FAQ
- This point in JS
- Does the oscilloscope probe affect the measurement of capacitive load?
- [untitled]
- layer.open 当传值为数组或值太长时处理方法
- JVM tuning related commands and explanations
- Flink sql -- No factory implements ‘org. apache. flink. table. delegation. ExecutorFactory‘.
- [untitled]
- Influencing factors of echo cancellation for smart speakers
猜你喜欢
Detailed explanation of pytoch's scatter function
Interpretation of source code demand:a rotation equivariant detector for aerial object detection
Pytorch BERT
Axure制作菜单栏效果
Detectron2 source code reading 4-- registrar construction model
[untitled]
Flink Exception -- No ExecutorFactory found to execute the application
Occasionally, Flink data is overstocked, resulting in checkpoint failure
el-input 限制只能输数字
Graffiti Wi Fi & ble SoC development slide strip
随机推荐
Qt通过Url下载文件
Detectron2 source code reading 4-- registrar construction model
Pytorch BERT
Flink SQL 自定义 Connector
【NVMe2.0b 14-3】Doorbell Buffer Config command、Device Self-test command
Gilbert Strang's course notes on linear algebra - Lesson 4
2021-02-18
This point in JS
[data analysis and display]
Interpretation of orientedrcnn papers
Build a docker image of Henkel database from 0
Unity简单shader
14岁懂社会-《关于“工作的幸福”这件事儿》读书笔记
2021-02-19
Icon resources
技术管理进阶——管理者如何进行梯队设计及建设
Interpretation of source code demand:a rotation equivariant detector for aerial object detection
Enter the URL in the browser and display it on the page
Is it safe to open an account? How can anyone say that it is not reliable.
Redis design and Implementation (II) | database (deletion strategy & expiration elimination strategy)