Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita0a76bb

Browse files
committed
final corrections
1 parentfd63f7c commita0a76bb

File tree

6 files changed

+38
-48
lines changed

6 files changed

+38
-48
lines changed

‎doc/tutorials/app/animations.markdown‎

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Working withAnimated Files {#tutorial_animations}
1+
HandlingAnimated Image Files {#tutorial_animations}
22
===========================
33

44
@tableofcontents
@@ -12,10 +12,10 @@ Goal
1212
----
1313
In this tutorial, you will learn how to:
1414

15-
- Use cv::imreadanimation to load frames from animated files.
16-
- Understand the structure and parameters of the cv::Animation structure.
15+
- Use`cv::imreadanimation` to load frames from animated image files.
16+
- Understand the structure and parameters of the`cv::Animation` structure.
1717
- Display individual frames from an animation.
18-
- Use cv::imwriteanimation to write cv::Animation to file.
18+
- Use`cv::imwriteanimation` to write`cv::Animation` to a file.
1919

2020
Source Code
2121
-----------
@@ -24,50 +24,36 @@ Source Code
2424
-**Downloadable code**: Click
2525
[here](https://github.com/opencv/opencv/tree/4.x/samples/cpp/tutorial_code/imgcodecs/animations.cpp)
2626

27-
-**Code at glance:**
27+
-**Code ataglance:**
2828
@include samples/cpp/tutorial_code/imgcodecs/animations.cpp
2929
@end_toggle
3030

3131
@add_toggle_python
3232
-**Downloadable code**: Click
3333
[here](https://github.com/opencv/opencv/tree/4.x/samples/python/tutorial_code/imgcodecs/animations.py)
3434

35-
-**Code at glance:**
35+
-**Code ataglance:**
3636
@include samples/python/tutorial_code/imgcodecs/animations.py
3737
@end_toggle
3838

39-
###Function Overview:
40-
41-
The cv::imreadanimation function is used to load multiple frames from animated files (such as AVIF, APNG, or WebP) into an cv::Animation structure.
42-
This function is especially useful for handling animated images, where each frame is a separate image that can be processed individually.
43-
44-
####Function Signature
45-
46-
```cpp
47-
CV_EXPORTS_Wboolimreadanimation(const String& filename, CV_OUT Animation& animation, int start = 0, int count = INT16_MAX);
48-
```
49-
50-
### Parameters
51-
52-
- filename: The path to the animated file, which must be in a supported animated format (e.g., AVIF, APNG, WebP).
53-
- animation: A reference to an cv::Animation structure where the frames will be stored.
54-
- start: The index of the first frame to load (optional, defaults to 0).
55-
- count: The number of frames to load (optional, defaults to 32767).
56-
5739
Explanation
5840
-----------
5941

60-
1. **Setting up the Animation Structure**
42+
1.**Initializing the Animation Structure**
6143

62-
Initializeancv::Animation structure to hold the frames from the animated file.
44+
Initializea`cv::Animation` structure to hold the frames from the animated image file.
6345

64-
```cpp
65-
Animation animation;
66-
```
46+
@add_toggle_cpp
47+
@snippet cpp/tutorial_code/imgcodecs/animations.cpp init_animation
48+
@end_toggle
49+
50+
@add_toggle_python
51+
@snippet python/tutorial_code/imgcodecs/animations.py init_animation
52+
@end_toggle
6753

6854
2.**Loading Frames**
6955

70-
Use cv::imreadanimation to load frames from the specified file. Here, we load all frames from an animated WebP image.
56+
Use`cv::imreadanimation` to load frames from the specified file. Here, we load all frames from an animated WebP image.
7157

7258
@add_toggle_cpp
7359
@snippet cpp/tutorial_code/imgcodecs/animations.cpp read_animation
@@ -101,5 +87,5 @@ Explanation
10187

10288
##Summary
10389

104-
The cv::imreadanimation and cv::imwriteanimation functions make it easy to work with animatedimagesby loading frames intoancv::Animation structure, allowing frame-by-frame processing.
105-
With these functions, you can load, process, and save frames from animatedformatslike AVIF, APNG, and WebP.
90+
The`cv::imreadanimation` and`cv::imwriteanimation` functions make it easy to work with animatedimage filesby loading frames intoa`cv::Animation` structure, allowing frame-by-frame processing.
91+
With these functions, you can load, process, and save frames from animatedimage fileslike GIF, AVIF, APNG, and WebP.

‎modules/imgcodecs/include/opencv2/imgcodecs.hpp‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -340,15 +340,15 @@ The function imreadmulti loads a specified range from a multi-page image from th
340340
CV_EXPORTS_Wboolimreadmulti(const String& filename, CV_OUT std::vector<Mat>& mats,int start,int count,int flags = IMREAD_ANYCOLOR);
341341

342342
/** @example samples/cpp/tutorial_code/imgcodecs/animations.cpp
343-
An example to show usage of imreadanimation and imwriteanimation functions.
343+
An example to show usage ofcv::imreadanimation andcv::imwriteanimation functions.
344344
Check @ref tutorial_animations "the corresponding tutorial" for more details
345345
*/
346346

347-
/** @brief Loadsimages from an animated file into an Animation structure.
347+
/** @brief Loadsframes from an animated image file into an Animation structure.
348348
349-
The function imreadanimation loads frames from an animated file (e.g., AVIF,PNG, WEBP) into the provided Animation struct.
349+
The function imreadanimation loads frames from an animatedimagefile (e.g.,GIF,AVIF,APNG, WEBP) into the provided Animation struct.
350350
351-
@param filename A string containing the path to the file. The file must be in a supported animated format (such as AVIF, PNG, or WebP).
351+
@param filename A string containing the path to the file.
352352
@param animation A reference to an Animation structure where the loaded frames will be stored. It should be initialized before the function is called.
353353
@param start The index of the first frame to load. This is optional and defaults to 0.
354354
@param count The number of frames to load. This is optional and defaults to 32767.
@@ -357,10 +357,10 @@ The function imreadanimation loads frames from an animated file (e.g., AVIF, PNG
357357
*/
358358
CV_EXPORTS_Wboolimreadanimation(const String& filename, CV_OUT Animation& animation,int start =0,int count = INT16_MAX);
359359

360-
/** @brief Saves ananimation to a specified file.
360+
/** @brief Saves anAnimation to a specified file.
361361
362362
The function imwriteanimation saves the provided Animation data to the specified file in an animated format.
363-
Supported formats depend on the implementation and may include formats like AVIF,PNG, or WEBP.
363+
Supported formats depend on the implementation and may include formats likeGIF,AVIF,APNG, or WEBP.
364364
365365
@param filename The name of the file where the animation will be saved. The file extension determines the format.
366366
@param animation A constant reference to an Animation struct containing the frames and metadata to be saved.

‎modules/imgcodecs/src/grfmt_avif.cpp‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ bool AvifDecoder::readData(Mat &img) {
242242
returnfalse;
243243
}
244244

245-
m_animation.durations.push_back(decoder_->duration);
245+
m_animation.durations.push_back(decoder_->imageTiming.durationInTimescales);
246246

247247
if (decoder_->image->exif.size >0) {
248248
m_exif.parseExif(decoder_->image->exif.data, decoder_->image->exif.size);
@@ -306,10 +306,10 @@ bool AvifEncoder::writemulti(const std::vector<Mat> &img_vec,
306306
const std::vector<int> &params) {
307307
Animation animation;
308308
animation.frames = img_vec;
309-
int timestamp =100;
309+
310310
for (size_t i =0; i < animation.frames.size(); i++)
311311
{
312-
animation.durations.push_back(timestamp);
312+
animation.durations.push_back(1000);
313313
}
314314
returnwriteanimation(animation, params);
315315
}
@@ -368,13 +368,11 @@ bool AvifEncoder::writeanimation(const Animation& animation,
368368
images.emplace_back(ConvertToAvif(img, do_lossless, bit_depth));
369369
}
370370

371-
int timestamp =0;
372371
for (size_t i =0; i < images.size(); i++)
373372
{
374373
OPENCV_AVIF_CHECK_STATUS(
375-
avifEncoderAddImage(encoder_, images[i].get(),timestamp, flag),
374+
avifEncoderAddImage(encoder_, images[i].get(),animation.durations[i], flag),
376375
encoder_);
377-
timestamp += animation.durations[i];
378376
}
379377

380378
encoder_->timescale =1000;

‎modules/imgcodecs/src/grfmt_base.hpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class BaseImageDecoder {
133133
*/
134134
virtualboolcheckSignature(const String& signature)const;
135135

136-
Animationanimation()const {return m_animation; };
136+
constAnimation&animation()const {return m_animation; };
137137

138138
/**
139139
* @brief Create and return a new instance of the derived image decoder.

‎samples/cpp/tutorial_code/imgcodecs/animations.cpp‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ int main( int argc, const char** argv )
2525
}
2626
//! [write_animation]
2727

28-
//! [read_animation]
28+
//! [init_animation]
2929
Animation animation;
30+
//! [init_animation]
31+
32+
//! [read_animation]
3033
bool success =imreadanimation(filename, animation);
3134
if (!success) {
3235
std::cerr <<"Failed to load animation frames\n";

‎samples/python/tutorial_code/imgcodecs/animations.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def main(filename):
1313
frames= []
1414
durations= []
1515

16-
# Populate frames andtimestamps in the Animation object
16+
# Populate frames anddurations in the Animation object
1717
foriinrange(10):
1818
frame=image.copy()
1919
cv.putText(frame,f"Frame{i}", (30,80),cv.FONT_HERSHEY_SIMPLEX,1.5, (255,100,0,255),2)
@@ -27,8 +27,11 @@ def main(filename):
2727
cv.imwriteanimation(filename,animation_to_save, [cv.IMWRITE_WEBP_QUALITY,100])
2828
## [write_animation]
2929

30-
## [read_animation]
30+
## [init_animation]
3131
animation=cv.Animation()
32+
## [init_animation]
33+
34+
## [read_animation]
3235
success,animation=cv.imreadanimation(filename)
3336
ifnotsuccess:
3437
print("Failed to load animation frames")

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp