当前位置:网站首页>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
边栏推荐
- QT downloading files through URL
- 电流探头电路分析
- Flink sql -- No factory implements ‘org. apache. flink. table. delegation. ExecutorFactory‘.
- 证券开户的优惠怎样才能得到?在线开户安全?
- C # listbox how to get the selected content (search many invalid articles)
- Rew acoustic test (V): equipment required for test
- CUDA implements matrix replication
- Rew acoustic test (IV): test principle of rew
- MIME type Encyclopedia
- JVM tuning related commands and explanations
猜你喜欢

Occasionally, Flink data is overstocked, resulting in checkpoint failure

Does the oscilloscope probe affect the measurement of capacitive load?

Redis design and Implementation (VII) | publish & subscribe

Codeworks 5 questions per day (1700 for each) - the third day

Bind threads to run on a specific CPU logical kernel

Redis design and Implementation (V) | sentinel sentry

codeforces每日5题(均1700)-第三天
![[kotlin collaboration process] complete the advanced kotlin collaboration process](/img/43/9c4b337caf406537e317dea2ed5f17.png)
[kotlin collaboration process] complete the advanced kotlin collaboration process

Rew acoustic test (I): microphone calibration

Redis design and Implementation (I) | data structure & object
随机推荐
Vite project require syntax compatibility problem solving require is not defined
Rew acoustic test (I): microphone calibration
Source code interpretation of detectron2 1--engine
2021-02-27
Pytorch BERT
C accesses mongodb and performs CRUD operations
icon资源
MIME type Encyclopedia
技术管理进阶——管理者如何进行梯队设计及建设
Flink Sql -- toAppendStream doesn‘t support consuming update and delete changes which
一次cpu 跌底排查
电流探头的干扰源电流谱测试
Torchvision loads the weight of RESNET except the full connection layer
Flink Exception -- No ExecutorFactory found to execute the application
Tidb 6.0: making Tso more efficient tidb Book rush
Conversion between map, string and JSON
Graffiti Wi Fi & ble SoC development slide strip
How can we get a satisfactory salary? These routines still need to be mastered
酒精测试仪方案:酒精测试仪是根据什么原理测酒精溶度?
Evaluation standard for audio signal quality of intelligent speakers