当前位置:网站首页>Opencv learning notes -day1 (image reading display imread, imshow, namedwindow)
Opencv learning notes -day1 (image reading display imread, imshow, namedwindow)
2022-06-30 08:47:00 【Chasing foot dream】
OpenCV Learning notes
day1- Image reading display
use OpenCV Development module , Open a picture in the host Directory ,
And displayed on the desktop
function :
highug Module imread,imshow,namedWindow,imwrite function
Mat imread(const string& filename, int flags=1)
| Parameters | explain |
|---|---|
| filename | Read the address file name of the file |
| flags | Read the color category of the image (flags=1:( Default parameters ) Said to return to 3 Channel image ;CV_LOAD_IMAGE_ANYEPTH: return 16bit or 32bit Images ( When entering the same depth ), Otherwise return to 8bit Images ;CV_LOAD_IMAGE_COLOR: Returns a monochrome image ;CV_LOAD_IMAGE_GRAYSCALE: Return to channel image ;0: Return to single channel image ;<0: Do not channel the image ;>0: Cast to 3 Channel image . |
example 1
// Image reading
Mat scr = imread("D:\\ Study \\OpenCV Study \\pictures\\image\\1.jpg");
- ,imshow() Display an image in the specified window
void imshow(const String& winname, InputArray mat);
| Parameters | explain |
|---|---|
| winname | const string& Type of winname, Refers to the window identification name to be displayed |
| mat | InputArray Type of mat, Refers to the image to be displayed |
notes:imshow() 1, Only support 8 Bits and floating-point numbers display RGB Color space ;
2, RGB Color space :B G R Three channels Three color combination 255255255 And transparent channels
example 2
imshow(" window 1",scr);// In the created window 1 Show
void namedWindow(const String& winname, int flags = WINDOW_AUTOSIZE);
| Parameters | explain |
|---|---|
| winname | const String& Of winname, The window name used as the window identifier |
| flags | The identification of the window , The general default is WINDOW_AUTOSIZE The size of the window is constrained by the displayed image |
notes:
CV_WINDOW_NORMAL Change the window to normal size or make it resizable ..
CV_WINDOW_AUTOSIZE The size of the window is constrained by the displayed image . The window is not resizable ..
CV_WINDOW_FULLSCREEN Change the window to full screen .
CV_WINDOW_FREERATIO Make windows resizable without ratio constraints .
CV_WINDOW_KEEPRATIO Make the window resizable , But keep the scale of the displayed image
example 3
namedWindow(" window 1", WINDOW_NORMAL);// establish WINDOW_FREERATIO window
int waitKey(int delay = 0);
waitKey The function is to constantly refresh the image , Frequency time delay, Unit is ms, The return value is the value pressed by the current keyboard , Return when there is no key -1
example 4
waitKey(0);// Infinite loop
while(1){
if(waitKey(100)==27)break; }
// In this program , tell OpenCv Wait for the user to trigger the event ,
// The waiting time is 100ms, If within this time period , The user presses ESC(ASCII Code for 27), And then jump out of the loop , otherwise , And then jump out of the loop
Code :
QuickDemo.cpp
#include <iostream>
#include <opencv2\highgui.hpp>
#include <opencv2\imgproc.hpp>
using namespace cv;
using namespace std;
int main()
{
Mat scr = imread("D:\\ Study \\OpenCV Study \\pictures\\image\\1.jpg");// Open a picture
if (!scr.data == 1)// Sentenced to empty
return -1;
namedWindow(" window 1", WINDOW_FREERATIO);// establish WINDOW_FREERATIO window
imshow(" window 1",scr);// Show in the created window
waitKey(0);// Time delay 0-> Constant delay 1-> Time delay 1ms
return 0;
}
notes:
The conditions for judging null ( As shown in the complete code above ):
1,scr.empty();// Determine whether it is a form ,if If it is not loaded successfully, it is blank ,print: could not laod image;
2,scr.data;//if(!scr.data)==1 Failed to read
边栏推荐
- 基于Svelte3.x桌面端UI组件库Svelte UI
- 【NVMe2.0b 14-2】Create/Delete Queue
- CUDA implements matrix replication
- Axure制作菜单栏效果
- vite項目require語法兼容問題解决require is not defined
- Redis设计与实现(七)| 发布 & 订阅
- Unity simple shader
- Graffiti Wi Fi & ble SoC development slide strip
- VIM from dislike to dependence (21) -- cross file search
- Map,String,Json之間轉換
猜你喜欢

Qt连接神通数据库

一次cpu 跌底排查

技术管理进阶——管理者如何进行梯队设计及建设

【NVMe2.0b 14-3】Doorbell Buffer Config command、Device Self-test command

【NVMe2.0b 14-2】Create/Delete Queue

Circuit analysis of current probe

Advanced technology management -- how managers design and build echelons

从0开始构建一个瀚高数据库Docker镜像

Tidb v6.0.0 (DMR): initial test of cache table - tidb Book rush

Redis design and Implementation (IV) | master-slave replication
随机推荐
Be careful of this hole in transmittable thread local
Bind threads to run on a specific CPU logical kernel
Mmdet line by line deltaxywhbboxcoder
证券开户的优惠怎样才能得到?在线开户安全?
[untitled]
增强for循环的增删操作 & 迭代器删除集合元素
电流探头的干扰源电流谱测试
C#访问SQL Server数据库两种方式的比较(SqlDataReader vs SqlDataAdapter)
Flink Sql -- toAppendStream doesn‘t support consuming update and delete changes which
Introduction to the runner of mmcv
Unity simple shader
Gilbert Strang's course notes on linear algebra - Lesson 3
2021-02-22
Enhance the add / delete operation of for loop & iterator delete collection elements
vite项目require语法兼容问题解决require is not defined
Redis design and Implementation (VIII) | transaction
从0开始构建一个瀚高数据库Docker镜像
Viteproject require Syntax Compatibility Problem Solving require is not defined
VIM from dislike to dependence (21) -- cross file search
Tidb 6.0: making Tso more efficient tidb Book rush