網站首頁 編程語言 正文
1.API和相關知識
1. rectangele?繪制矩形
共7個參數
?? ??? ??? ?第1個參數 輸入
?? ??? ??? ?第2個參數 矩形左上坐標
?? ??? ??? ?第3個參數 矩形右下坐標
?? ??? ??? ?第4個參數 矩形顏色
?? ??? ??? ?第5個參數 線寬
?? ??? ??? ??? ??? ??? ??? ?如果參數 >=0,則表示繪制矩形(如為1,表示繪制的矩形邊為1個像素)
?? ??? ??? ??? ??? ??? ??? ?如果參數 < 0,則表示填充矩形(如-1,表示填充整個矩形)
?? ??? ??? ?第6個參數 lineType
?? ??? ??? ??? ??? ??? ??? ?關于圖像鋸齒,有幾種方式處理
?? ??? ??? ??? ??? ??? ??? ??? ?不管不顧,就用LINE_4 或者 LINE_8
?? ??? ??? ??? ??? ??? ??? ??? ?消除鋸齒,就用LINE_AA (AA就是反鋸齒)
?? ??? ??? ?第7個參數 ?縮小圖像,同時縮短矩形左上頂點與(0,0)位置的距離(一般沒用)
?? ??? ??? ??? ??? ? ?0表示不變
?? ??? ??? ??? ??? ? ?1表示圖像*1/2,同時距離(0,0)的x方向和y方向距離*1/2
?? ??? ??? ??? ??? ? ?2表示圖像*(1/2)^2,同時距離(0,0)的x方向和y方向距離*(1/2)^2
第二種
rectangele
?? ?繪制矩形
?? ??? ?共6個參數
?? ??? ??? ?第1個參數 輸入
?? ??? ??? ?第2個參數 矩形的左上點+往對角方向延伸的距離(x1,x2,延伸長度1,延伸長度2)
?? ??? ??? ?第3個參數 矩形顏色
?? ??? ??? ?第4個參數 線寬
?? ??? ??? ??? ??? ??? ??? ?如果參數 >=0,則表示繪制矩形(如為1,表示繪制的矩形邊為1個像素)
?? ??? ??? ??? ??? ??? ??? ?如果參數 < 0,則表示填充矩形(如-1,表示填充整個矩形)
?? ??? ??? ?第5個參數 lineType
?? ??? ??? ??? ??? ??? ??? ?關于圖像鋸齒,有幾種方式處理
?? ??? ??? ??? ??? ??? ??? ??? ?不管不顧,就用LINE_4 或者 LINE_8
?? ??? ??? ??? ??? ??? ??? ??? ?消除鋸齒,就用LINE_AA (AA就是反鋸齒)
?? ??? ??? ?第6個參數 ?縮小圖像,同時縮短矩形左上頂點與(0,0)位置的距離
?? ??? ??? ??? ??? ? ?0表示不變
?? ??? ??? ??? ??? ? ?1表示圖像*1/2,同時距離(0,0)的x方向和y方向距離*1/2
?? ??? ??? ??? ??? ? ?2表示圖像*(1/2)^2,同時距離(0,0)的x方向和y方向距離*(1/2)^2
?
void QuickDemo::bitwise_demo(Mat& image) {
Mat m1 = Mat::zeros(Size(256, 256), CV_8UC3);
Mat m2 = Mat::zeros(Size(256, 256), CV_8UC3);
//rectangle有兩種傳參方式,這里分別進行了示范
rectangle(m1, Point(100, 100), Point(180, 180), 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);
imshow("m2", m2);
}
2.位運算
在opencv中,圖像的為運算有4種
- 與
- 或
- 非
- 異或
bitwise_and(m1, m2, dst);
//bitwise_or(m1, m2, dst);
//bitwise_not(m1, dst);
//bitwise_xor(m1, m2, dst);略
2.實例代碼
void QuickDemo::bitwise_demo(Mat& image) {
Mat m1 = Mat::zeros(Size(256, 256), CV_8UC3);
Mat m2 = Mat::zeros(Size(256, 256), CV_8UC3);
rectangle(m1, Point(100, 100), Point(180, 180), Scalar(255, 255, 0), -1, LINE_4,0);
rectangle(m2, Rect(150, 150, 80, 80), Scalar(0, 255, 255), -1, 0);
Mat dst;
bitwise_and(m1, m2, dst);
//bitwise_or(m1, m2, dst);
//bitwise_not(m1, dst);
//bitwise_xor(m1, m2, dst);
imshow("位運算",dst);
}
補充:OpenCV--C++圖像像素處理-二值化
#include<opencv2/opencv.hpp>
#include<iostream>
#include<vector>
using namespace std;
using namespace cv;
int main()
{
Mat img = imread("colors.jpg");
if (img.empty()) {
cout << "圖片讀取失敗" << endl;
}
Mat gray;
cvtColor(img, gray, COLOR_BGR2GRAY); //將RGB圖像img轉為灰度圖gray
// 彩圖BINARY二值化
Mat binary, binary_inv;
threshold(img, binary, 125, 255, THRESH_BINARY);
threshold(img, binary_inv, 125, 255, THRESH_BINARY_INV);
imshow("binary", binary);
imshow("binary_inv", binary_inv);
//灰度圖BINARY二值化
Mat binary_gray, binary_gray_inv;
threshold(gray, binary_gray, 125, 255,THRESH_BINARY);
threshold(gray, binary_gray_inv,125, 255, THRESH_BINARY_INV);
imshow("binary_gray", binary_gray);
imshow("binary_gray_inv", binary_gray_inv);
//灰度圖TOZERO二值化
Mat tozero_gray, tozero_gray_inv;
threshold(gray, tozero_gray, 125, 255, THRESH_TOZERO);
threshold(gray, tozero_gray_inv, 125, 255, THRESH_TOZERO_INV);
imshow("tozero_gray", binary_gray);
imshow("tozero_gray_inv", binary_gray_inv);
//灰度圖TRUNC二值化
Mat trunc_gray;
threshold(gray, trunc_gray, 125, 255, THRESH_TRUNC);
imshow("trunc_gray", trunc_gray);
Mat gray_thr = imread("colors.jpg", IMREAD_GRAYSCALE);
//灰度圖OSTU二值化
Mat otsu_gray;
threshold(gray_thr, otsu_gray, 100, 255,THRESH_BINARY | THRESH_OTSU);
imshow("trunc_gray", otsu_gray);
//灰度圖triangle二值化
Mat triangle_gray;
threshold(gray_thr, triangle_gray, 100, 255, THRESH_BINARY | THRESH_TRIANGLE);
imshow("triangle_gray", triangle_gray);
//灰度圖自適應二值化
Mat adapt_mean_gray;
adaptiveThreshold(gray_thr, adapt_mean_gray, 255, ADAPTIVE_THRESH_MEAN_C, THRESH_BINARY, 55, 0);
imshow("adapt_mean_gray", adapt_mean_gray);
Mat adapt_gauss_gray;
adaptiveThreshold(gray_thr, adapt_gauss_gray, 255, ADAPTIVE_THRESH_GAUSSIAN_C, THRESH_BINARY, 55, 0);
imshow("adapt_gauss_gray", adapt_gauss_gray);
waitKey(0);
return 0;
}
總結
原文鏈接:https://blog.csdn.net/weixin_46098612/article/details/127774177
相關推薦
- 2022-05-03 shell腳本批量創建用戶的方法小結_linux shell
- 2022-06-23 Python+Turtle制作獨特的表白圖_python
- 2022-10-23 python如何在一個py文件中獲取另一個py文件中的值(一個或多個)_python
- 2024-01-31 linux下查看文件當下的所有文件的大小和查找大文件
- 2022-09-18 GO實現文件上傳操作_Golang
- 2023-03-15 Python多進程協作模擬實現流程_python
- 2022-04-28 C語言動態開辟內存詳解_C 語言
- 2022-07-22 服務器配置uWSGI+Nginx+Django
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支