Create a slide show of images in a folder with smooth transition between images

前言

题目地址:https://docs.opencv.org/4.x/d0/d86/tutorial_py_image_arithmetics.html
题目内容:
Create a slide show of images in a folder with smooth transition between images using cv.addWeighted function

Source Code

# 开发时间:2022/2/20  22:15
# Create a slide show of images in a folder with smooth transition between images using cv.addWeighted function
import os
import time
import cv2 as cv


def get_absolute_filename():
    '''
    获取指定文件夹下的绝对文件名
    :return:
    '''
    # base_path是图片所在的文件路径
    base_path = r'D:\pycharm_professional\PycharmProjects\fisrt_try_of_opencv\opencv\test\test_img'
    # absolute_filenames 用于存储图片绝对路径
    absolute_filenames = []
    # 循环取出文件名并拼接成绝对路径
    for filename in os.listdir(base_path):
        # print("filename:\n",filename)
        absolute_filenames.append(os.path.join(base_path,filename))
    # print("absolute_filenames:\n",absolute_filenames)
    return absolute_filenames

def get_img(filenames):
    '''
    获取图片对象
    :param filenames:
    :return:
    '''
    img = cv.imread(filenames[0])
    print("filenames[0]\n",filenames[0])
    print("img.shape:\n",img.shape)
    del filenames[0]
    return img

def read_img_smooth_transition():
    '''
    平滑的阅读图片
    :return:
    '''
    global k
    filenames = get_absolute_filename()
    while True:
        # 获取第一个图片对象
        try:
            img1 = get_img(filenames)
            img1 = img1[0:480,0:600]   # 取出图片指定大小的部分
        except:
            break
        # 获取第二个图片对象
        try:
            img2 = get_img(filenames)
            img2 = img2[0:480, 0:600]  # 取出图片指定大小的部分
        except:
            break

        i = 0
        for j in range(11):
            # 一定要注意叠加前需要保证两张图片的尺寸相同 where arrays have the same size and the same number of channels
            dst = cv.addWeighted(img1,i,img2,1-i,0)
            i = 0.1 * j
            cv.imshow("dst",dst)
            k = cv.waitKey(25) & 0xFF   # 指定每帧显示25毫秒
            if k == 27:    # 按esc键退出
                break

        if k == 27:    # 按esc键退出
            break


if __name__ == "__main__":
    # get_absolute_filename()
    read_img_smooth_transition()
    cv.destroyAllWindows()

Result

效果就像小视频一样,这里就不放视频演示了,直接粘贴下来使用的时候注意要修改路径。

总结

参考代码地址:
https://docs.opencv.org/4.x/d0/d86/tutorial_py_image_arithmetics.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
To create a SPA in React, we can use React Router. Here's an example of how to create a SPA in React with proper navigation: 1. First, create a new React app using `create-react-app`. 2. Install React Router by running the following command in your terminal: ``` npm install react-router-dom ``` 3. In your `src` folder, create a new folder called `pages`. Inside this folder, create a new file for each of your pages. For example, you could create a `Home.js` file and a `About.js` file. 4. In each of your page files, create a React component that represents that page. For example: ```jsx import React from 'react'; function Home() { return ( <div> <h1>Welcome to my website!</h1> <p>Here is some content.</p> </div> ); } export default Home; ``` 5. In your `App.js` file, import `BrowserRouter` from `react-router-dom` and wrap your entire app in it. Then, create a `Switch` component that will render the appropriate page based on the URL. ```jsx import React from 'react'; import { BrowserRouter, Switch, Route, Link } from 'react-router-dom'; import Home from './pages/Home'; import About from './pages/About'; function App() { return ( <BrowserRouter> <nav> <ul> <li> <Link to="/">Home</Link> </li> <li> <Link to="/about">About</Link> </li> </ul> </nav> <Switch> <Route path="/about"> <About /> </Route> <Route path="/"> <Home /> </Route> </Switch> </BrowserRouter> ); } export default App; ``` 6. In the example above, we're using `Link` components to create links to our pages, and we're using `Route` components to specify which component should be rendered for each URL. The `Switch` component ensures that only one page is rendered at a time. 7. Start your app by running `npm start` in your terminal. You should see your navigation links and be able to navigate between your pages.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

布兹学长

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值