├── .gitignore ├── Research Paper.pdf ├── presentation.odp ├── README.md ├── LICENSE ├── SceneChangeDetection.py └── Scene Change Detection.ipynb /.gitignore: -------------------------------------------------------------------------------- 1 | sample/ 2 | *.png 3 | -------------------------------------------------------------------------------- /Research Paper.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sandeepnmenon/Scene-Change-Detection/HEAD/Research Paper.pdf -------------------------------------------------------------------------------- /presentation.odp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sandeepnmenon/Scene-Change-Detection/HEAD/presentation.odp -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Scene-Change-Detection 2 | Detects scene change in a video file 3 | ## Execution 4 | python SceneChangeDetection \ 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Sandeep 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /SceneChangeDetection.py: -------------------------------------------------------------------------------- 1 | 2 | import sys 3 | import numpy as np 4 | import cv2 5 | 6 | try: 7 | file_name=str(sys.argv[1]) 8 | cap = cv2.VideoCapture(file_name) 9 | except: 10 | print "File not found. Give valid file path as fisrt command line argument" 11 | sys.exit() 12 | cnt=10 13 | 14 | 15 | def LBP(frame): 16 | for i in range(len(frame)): 17 | for j in range(len(frame[0])): 18 | if i==0 or j==0 or i==len(frame)-1 or j==len(frame[0])-1: 19 | continue 20 | try: 21 | gc=frame[i][j] 22 | newvalue=0 23 | if frame[i-1][j-1]>=gc: 24 | newvalue+=1 25 | if frame[i-1][j]>=gc: 26 | newvalue+=2 27 | if frame[i-1][j+1]>=gc: 28 | newvalue+=4 29 | if frame[i][j+1]>=gc: 30 | newvalue+=8 31 | if frame[i+1][j+1]>=gc: 32 | newvalue+=16 33 | if frame[i+1][j]>=gc: 34 | newvalue+=32 35 | if frame[i+1][j-1]>=gc: 36 | newvalue+=64 37 | if frame[i][j-1]>=gc: 38 | newvalue+=128 39 | 40 | frame[i][j]=newvalue 41 | except: 42 | print i,j 43 | return frame 44 | 45 | 46 | 47 | def getCuts(cap): 48 | num=0 49 | aslbphd=[] 50 | cnt=0 51 | while(True): 52 | 53 | ret, frame = cap.read() 54 | # Our operations on the frame come here 55 | gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) 56 | disFrame=frame 57 | frame=LBP(gray) 58 | if num==0: 59 | prevframe=frame 60 | num+=1 61 | continue 62 | 63 | num+=1 64 | diff=0 65 | lbph=cv2.calcHist([frame],[0],None,[256],[0,256]) 66 | prevlbph=cv2.calcHist([prevframe],[0],None,[256],[0,256]) 67 | for i in range(256): 68 | diff+=abs(lbph[i]-prevlbph[i]) 69 | 70 | if diff[0]>=25000: 71 | cnt+=1 72 | print "CUT "+str(cnt)+" Detected at frame "+str(num) 73 | aslbphd.append(diff) 74 | prevframe=frame 75 | # Display the resulting frame 76 | cv2.imshow('frame',disFrame) 77 | if cv2.waitKey(1) & 0xFF == ord('q'): 78 | break 79 | 80 | cap.release() 81 | cv2.destroyAllWindows() 82 | print num 83 | 84 | 85 | getCuts(cap) 86 | 87 | 88 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /Scene Change Detection.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 14, 6 | "metadata": { 7 | "collapsed": true 8 | }, 9 | "outputs": [], 10 | "source": [ 11 | "import numpy as np\n", 12 | "import cv2" 13 | ] 14 | }, 15 | { 16 | "cell_type": "code", 17 | "execution_count": 15, 18 | "metadata": { 19 | "collapsed": false 20 | }, 21 | "outputs": [], 22 | "source": [ 23 | "cap = cv2.VideoCapture('arjun.3gp')\n", 24 | "cnt=10\n" 25 | ] 26 | }, 27 | { 28 | "cell_type": "code", 29 | "execution_count": 16, 30 | "metadata": { 31 | "collapsed": false 32 | }, 33 | "outputs": [], 34 | "source": [ 35 | "def LBP(frame):\n", 36 | " for i in range(len(frame)):\n", 37 | " for j in range(len(frame[0])):\n", 38 | " if i==0 or j==0 or i==len(frame)-1 or j==len(frame[0])-1:\n", 39 | " continue\n", 40 | " try: \n", 41 | " gc=frame[i][j]\n", 42 | " newvalue=0\n", 43 | " if frame[i-1][j-1]>=gc:\n", 44 | " newvalue+=1\n", 45 | " if frame[i-1][j]>=gc:\n", 46 | " newvalue+=2\n", 47 | " if frame[i-1][j+1]>=gc:\n", 48 | " newvalue+=4\n", 49 | " if frame[i][j+1]>=gc:\n", 50 | " newvalue+=8\n", 51 | " if frame[i+1][j+1]>=gc:\n", 52 | " newvalue+=16\n", 53 | " if frame[i+1][j]>=gc:\n", 54 | " newvalue+=32\n", 55 | " if frame[i+1][j-1]>=gc:\n", 56 | " newvalue+=64\n", 57 | " if frame[i][j-1]>=gc:\n", 58 | " newvalue+=128\n", 59 | "\n", 60 | " frame[i][j]=newvalue\n", 61 | " except:\n", 62 | " print i,j\n", 63 | " return frame" 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": 17, 69 | "metadata": { 70 | "collapsed": false 71 | }, 72 | "outputs": [], 73 | "source": [ 74 | "def getCuts(cap):\n", 75 | " num=0\n", 76 | " aslbphd=[]\n", 77 | " cnt=0\n", 78 | " while(True):\n", 79 | "\n", 80 | " try: \n", 81 | " ret, frame = cap.read()\n", 82 | " # Our operations on the frame come here\n", 83 | " gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)\n", 84 | " disFrame=frame\n", 85 | " frame=LBP(gray)\n", 86 | " if num==0:\n", 87 | " prevframe=frame\n", 88 | " num+=1\n", 89 | " continue\n", 90 | "\n", 91 | " num+=1\n", 92 | " diff=0\n", 93 | " lbph=cv2.calcHist([frame],[0],None,[256],[0,256])\n", 94 | " prevlbph=cv2.calcHist([prevframe],[0],None,[256],[0,256])\n", 95 | " for i in range(256):\n", 96 | " diff+=abs(lbph[i]-prevlbph[i])\n", 97 | "\n", 98 | " if diff[0]>=25000:\n", 99 | " cnt+=1\n", 100 | " print \"CUT \"+str(cnt)+\" Detected at frame \"+str(num)\n", 101 | " aslbphd.append(diff)\n", 102 | " prevframe=frame\n", 103 | " # Display the resulting frame\n", 104 | " cv2.imshow('frame',disFrame)\n", 105 | " if cv2.waitKey(1) & 0xFF == ord('q'):\n", 106 | " break\n", 107 | " \n", 108 | " except:\n", 109 | " print num\n", 110 | " break\n", 111 | "\n", 112 | " cap.release()\n", 113 | " cv2.destroyAllWindows()\n", 114 | " print num" 115 | ] 116 | }, 117 | { 118 | "cell_type": "code", 119 | "execution_count": 18, 120 | "metadata": { 121 | "collapsed": false 122 | }, 123 | "outputs": [ 124 | { 125 | "name": "stdout", 126 | "output_type": "stream", 127 | "text": [ 128 | "CUT 1 Detected at frame 90\n", 129 | "CUT 2 Detected at frame 121\n", 130 | "CUT 3 Detected at frame 174\n", 131 | "CUT 4 Detected at frame 219\n", 132 | "CUT 5 Detected at frame 221\n", 133 | "CUT 6 Detected at frame 237\n", 134 | "CUT 7 Detected at frame 239\n", 135 | "CUT 8 Detected at frame 242\n", 136 | "CUT 9 Detected at frame 244\n", 137 | "CUT 10 Detected at frame 372\n", 138 | "CUT 11 Detected at frame 378\n", 139 | "CUT 12 Detected at frame 379\n", 140 | "CUT 13 Detected at frame 384\n", 141 | "CUT 14 Detected at frame 385\n", 142 | "CUT 15 Detected at frame 390\n", 143 | "CUT 16 Detected at frame 391\n", 144 | "CUT 17 Detected at frame 397\n", 145 | "CUT 18 Detected at frame 398\n", 146 | "CUT 19 Detected at frame 404\n", 147 | "CUT 20 Detected at frame 406\n", 148 | "CUT 21 Detected at frame 415\n", 149 | "CUT 22 Detected at frame 482\n", 150 | "CUT 23 Detected at frame 552\n", 151 | "CUT 24 Detected at frame 684\n", 152 | "CUT 25 Detected at frame 711\n", 153 | "CUT 26 Detected at frame 849\n", 154 | "CUT 27 Detected at frame 880\n", 155 | "CUT 28 Detected at frame 903\n", 156 | "CUT 29 Detected at frame 928\n", 157 | "CUT 30 Detected at frame 948\n", 158 | "CUT 31 Detected at frame 978\n", 159 | "CUT 32 Detected at frame 1024\n", 160 | "1124\n", 161 | "1124\n" 162 | ] 163 | } 164 | ], 165 | "source": [ 166 | "getCuts(cap)" 167 | ] 168 | }, 169 | { 170 | "cell_type": "code", 171 | "execution_count": null, 172 | "metadata": { 173 | "collapsed": true 174 | }, 175 | "outputs": [], 176 | "source": [] 177 | } 178 | ], 179 | "metadata": { 180 | "kernelspec": { 181 | "display_name": "Python 2", 182 | "language": "python", 183 | "name": "python2" 184 | }, 185 | "language_info": { 186 | "codemirror_mode": { 187 | "name": "ipython", 188 | "version": 2 189 | }, 190 | "file_extension": ".py", 191 | "mimetype": "text/x-python", 192 | "name": "python", 193 | "nbconvert_exporter": "python", 194 | "pygments_lexer": "ipython2", 195 | "version": "2.7.12" 196 | } 197 | }, 198 | "nbformat": 4, 199 | "nbformat_minor": 2 200 | } 201 | --------------------------------------------------------------------------------