Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize Image Reading and Writing by OpenCV

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article is about how OpenCV can read and write images. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Image operation

Image processing.

CvtColor (matobj1,printmatobj,CV_BGR2GRAY) / / Image 1 grayscale processing, save to image 2Canny (edges,edges,0,30,0); / / extract edges, save to image 2

Image display

NamedWindow ("printmatobj", 1); / / create a window imshow ("printmatobj", printmatobj); / / display to the window to read and write images

Use two functions to read and write files

Read image file

Imread function:

Enter the file path, and the number of channels that return the image, and the image is converted to a matrix

Empty method:

Check whether the read is successful

Write image file

Use the imwrite function to enter the file path, file format, file format details, matrix conversion to the image to save to the specified path

Read and write video

Use two classes to read and write files

VideoCapture

Classes that read videos

Open method / / Open camera or video isOpened method / / check whether the read method is opened successfully / / read an image VideoCaptureobj > > Matobj// read an image

VideoWriter

Classes that output video

Codec:

In CV_Fourcc format, if the coding is not successful, use another codec instead.

Size s (320240); / / define video width and height

VideoWirter writer=VideoWirter (filename,decoder,rate,size) / / set file name, codec, frame rate, width, height parameters

IsOpened method / / check whether the VideoWriterobj has been created successfully

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report