{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "# we need to read frames from the movie\n", "# so we install opencv-python - change the next cell type to \"Code\"" ] }, { "cell_type": "raw", "metadata": {}, "source": [ "!pip install opencv-python" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "ename": "ModuleNotFoundError", "evalue": "No module named 'cv2'", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mimport\u001b[0m \u001b[0mcv2\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'cv2'" ] } ], "source": [ "import cv2" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import matplotlib.pyplot as plt" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from openpiv import pyprocess, piv" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# the video is the jet PIV from Youtube\n", "# https://www.youtube.com/watch?v=EeS1rYMZUxI&ab_channel=USUExperimentalFluidDynamicsLab\n", "# all the rights reserved to the authors\n", "\n", "vidcap = cv2.VideoCapture('../test_movie/videoplayback.mp4')\n", "success, image1 = vidcap.read()\n", "count = 0\n", "U = []\n", "V = []\n", "\n", "while success and count < 10:\n", " # cv2.imwrite(\"frame%d.jpg\" % count, image) # save frame as JPEG file \n", " success, image2 = vidcap.read()\n", " # print('Read a new frame: ', success)\n", " if success:\n", " x,y,u,v = piv.simple_piv(image1.sum(axis=2), image2.sum(axis=2),plot=True);\n", " image1 = image2.copy()\n", " count += 1\n", " U.append(u)\n", " V.append(v)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "U = np.stack(U)\n", "Umean = np.mean(U, axis=0)\n", "V = np.stack(V)\n", "Vmean = np.mean(V,axis=0)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fig,ax = plt.subplots(figsize=(8,8))\n", "ax.imshow(image1,alpha=0.7)\n", "ax.quiver(x,y,Umean,Vmean,scale=200,color='r',width=.008)\n", "# plt.show()\n", "plt.plot(np.mean(Umean,axis=1)*20,y[:,0],color='y',lw=3)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python [conda env:openpiv] *", "language": "python", "name": "conda-env-openpiv-py" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.5" } }, "nbformat": 4, "nbformat_minor": 4 }