Commit 48cf59a7 authored by Gihan Jayatilaka's avatar Gihan Jayatilaka

setup 2

parent f37a47f5
......@@ -10,19 +10,18 @@ import time
DEBUG = 0
NUMPATTERN = 20000
REPEAT = 20
GRID_X = 20
GRID_Y = 20
NO_FRAMES_MAX = 8000
#REPEAT = 20
GRID_X = 3
GRID_Y = 3
GAUSS = 0
DELTA = 5
NUMPAT33 = 384
#NUMPAT33 = 384
READ_FILE = "../drone"
READ_FILE = "../tvstatic"
EXTENSION = ".mp4"
OUT_FILE = "{}-code-{}x{}".format(READ_FILE,GRID_Y,GRID_X)
......@@ -30,14 +29,19 @@ WIDTH = 1920
HEIGHT = 1080
try:
FILE = sys.argv[1]
GAUSS = int(sys.argv[2])
DELTA = int(sys.argv[3])
'''try:
GRID_X=GRID_Y=int(sys.argv[2])
except:
print("Using hardcoded gauss={} delta={} values".format(GAUSS,DELTA))
print("Using hardcoded gauss={} delta={} values".format(GAUSS,DELTA))'''
READ_FILE=sys.argv[1]
EXTENSION=sys.argv[2]
GRID_X=GRID_Y=int(sys.argv[3])
READ_FILE_NAME=READ_FILE+EXTENSION
OUT_FILE = "{}-code-{}x{}".format(READ_FILE,GRID_Y,GRID_X)
READ_FILE_NAME=READ_FILE+'.'+EXTENSION
OUT_VIDEO_FILE_NAME=OUT_FILE+".mp4"
OUT_CSV_FILE_NAME=OUT_FILE+".csv"
......@@ -83,7 +87,7 @@ inputVideo = cv2.VideoCapture(READ_FILE_NAME)
frameindex = 0
for patindex in range(int(NUMPATTERN)):
for patindex in range(int(NO_FRAMES_MAX)):
ret, frame = inputVideo.read()
if ret:
......@@ -107,7 +111,7 @@ for patindex in range(int(NUMPATTERN)):
img = cv2.cvtColor(img, cv2.COLOR_LAB2BGR)
video.write(img)
patfile.write(str(code) + "\n")
print("Pattern: " + str(patindex) + ", Image name: " + str(frameindex))
if patindex%20==0: print("Pattern: " + str(patindex) + ", Image name: " + str(frameindex))
else:
break
frameindex += 1
......
......@@ -2,14 +2,14 @@
"cells": [
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"X shape (10000, 360, 480, 3) Y shape (10000, 25)\n"
"X shape (25000, 299, 299, 3) Y shape (25000, 100)\n"
]
}
],
......@@ -17,7 +17,6 @@
"'''\n",
"This script is used to verify the dataset created\n",
"All you have to do is to change the FILE_NAME variable and run the program\n",
"\n",
"'''\n",
"\n",
"import numpy as np\n",
......@@ -26,8 +25,8 @@
"import random\n",
"import math\n",
"random.seed(625742)\n",
"FILE_NAME='../../video/nature-5x5.npz'\n",
"NO_FRAMES_TO_CHECK=100\n",
"FILE_NAME='../../video/videos-ideal-10x10-shuffled.npz'\n",
"NO_FRAMES_TO_CHECK=10\n",
"SHELL=False\n",
"\n",
"\n",
......@@ -47,23 +46,20 @@
"\n",
"\n",
"def genImage(label):\n",
" frame=np.zeros((X.shape[1],X.shape[2],3),dtype=np.uint8)\n",
" frame=np.zeros((299,299,3),dtype=np.uint8)\n",
" noCellsSqrt=int(math.sqrt(len(label)))\n",
" h=cellHeight=int(frame.shape[0]/noCellsSqrt)\n",
" w=cellWidth=int(frame.shape[1]/noCellsSqrt)\n",
" for y in range(noCellsSqrt):\n",
" for x in range(noCellsSqrt):\n",
"# print(x,y,noCellsSqrt,h,w)\n",
" frame[y*h:(y+1)*h,x*w:(x+1)*w,:]=label[y*noCellsSqrt+x]*255\n",
" \n",
"# print(label[y*noCellsSqrt+x])\n",
" frame=cv2.flip(frame,-1)\n",
" frame=cv2.transpose(frame,-1)\n",
" return frame\n",
" \n",
"\n",
"for f in range(NO_FRAMES_TO_CHECK):\n",
" i=random.randint(0,X.shape[0]-1)\n",
" #print(i,Y[i],'\\r')\n",
" l=genImage(Y[i])\n",
"\n",
" cv2.imshow(\"Image\",X[i])\n",
......
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import cv2\n",
"import sys\n",
"\n",
"data=np.load('../butterfly-20x20.npz')\n",
"X=data['X']\n",
"Y=data['Y']\n",
"\n",
"\n",
"print(\"DEBUG: \",\"X\",X.shape,\"Y\",Y.shape)\n",
"\n",
"\n",
"\n",
"for i in range(X.shape[0]):\n",
" cv2.imshow(\"Image\",X[i])\n",
" cv2.waitKey(0)\n",
" print(i,Y[i])\n",
" \n",
"cv2.destroyAllWindows()\n",
"\n",
" \n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"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.5.6"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
#!/usr/bin/env python
# coding: utf-8
# In[ ]:
import numpy as np
import cv2
import sys
data=np.load('../video/butterfly.npz')
X=data['X']
Y=data['Y']
print("DEBUG: ","X",X.shape,"Y",Y.shape)
N=int(sys.argv[1])
print(Y[N])
cv2.imshow("Image",X[N])
cv2.waitKey(100000000)
for i in range(X.shape[0]):
#idx=int(input())
#cv2.ion()
cv2.imshow("Image",X[i])
cv2.waitKey(10)
print(i,Y[i])
cv2.destroyAllWindows()
# In[ ]:
# In[ ]:
......@@ -2,31 +2,26 @@
"cells": [
{
"cell_type": "code",
"execution_count": 8,
"execution_count": null,
"metadata": {},
"outputs": [
{
"ename": "FileNotFoundError",
"evalue": "[Errno 2] No such file or directory: '../../video/butterfly-code-20x20.csv'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mFileNotFoundError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-8-5f03600d6eff>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 20\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 21\u001b[0m \u001b[0mvideo\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcv2\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mVideoCapture\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'{}-code-{}x{}.mp4'\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mformat\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mFILE_NAME\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mGRID_X\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mGRID_Y\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 22\u001b[0;31m \u001b[0mpattern\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mopen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'{}-code-{}x{}.csv'\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mformat\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mFILE_NAME\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mGRID_X\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mGRID_Y\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 23\u001b[0m \u001b[0mnpzFile\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m'{}-ideal-{}x{}.npz'\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mformat\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mFILE_NAME\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mGRID_X\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mGRID_Y\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 24\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: '../../video/butterfly-code-20x20.csv'"
]
}
],
"outputs": [],
"source": [
"FILE_NAME='../../video/butterfly'\n",
"GRID_X=20\n",
"GRID_Y=20\n",
"import cv2\n",
"import numpy as np\n",
"import sys\n",
"\n",
"FILE_NAME='../tvstatic'\n",
"GRID_X=10\n",
"GRID_Y=10\n",
"\n",
"if len(sys.argv)>3:\n",
" FILE_NAME=(sys.argv[1].split(\"-\"))[0]\n",
" GRID_X=int(sys.argv[2])\n",
" GRID_Y=int(sys.argv[3])\n",
"\n",
"CELLS_PER_FRAME=GRID_X*GRID_Y\n",
"\n",
"import cv2\n",
"import numpy as np\n",
"\n",
"\n",
"def binArray(x):\n",
" ans=np.zeros((CELLS_PER_FRAME),dtype=np.uint8)\n",
......@@ -54,6 +49,11 @@
" XX.append(frame)\n",
" else:\n",
" break\n",
" \n",
" if len(YY)==8000:\n",
" break\n",
" \n",
" \n",
"video.release()\n",
"pattern.close()\n",
"\n",
......
#!/usr/bin/env python
# coding: utf-8
# In[1]:
import cv2
import numpy as np
import sys
FILE_NAME='../tvstatic'
GRID_X=20
GRID_Y=20
if len(sys.argv)>3:
FILE_NAME=(sys.argv[1].split("-"))[0]
GRID_X=int(sys.argv[2])
GRID_Y=int(sys.argv[3])
CELLS_PER_FRAME=GRID_X*GRID_Y
def binArray(x):
ans=np.zeros((CELLS_PER_FRAME),dtype=np.uint8)
for i in range(CELLS_PER_FRAME):
ans[i]=x&1
x=x>>1
return ans
video = cv2.VideoCapture('{}-code-{}x{}.mp4'.format(FILE_NAME,GRID_X,GRID_Y))
pattern = open('{}-code-{}x{}.csv'.format(FILE_NAME,GRID_X,GRID_Y))
npzFile = '{}-ideal-{}x{}.npz'.format(FILE_NAME,GRID_X,GRID_Y)
XX=[]
YY=[]
while video.isOpened():
ret, frame = video.read()
pat = pattern.readline()
if ret:
YY.append(binArray(int(pat)))
frame=cv2.resize(frame,(299,299),interpolation = cv2.INTER_LINEAR)
XX.append(frame)
else:
break
if len(YY)==8000:
break
video.release()
pattern.close()
XX=np.array(XX)
YY=np.array(YY)
np.savez(npzFile, X=XX, Y=YY)
print("X shape",XX.shape,"Y shape",YY.shape)
# In[ ]:
......@@ -2,30 +2,32 @@
"cells": [
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 16,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Up to file 0. X=(5000, 400) Y=(5000, 299, 299, 3).\n",
"Up to file 1. X=(10000, 400) Y=(10000, 299, 299, 3).\n",
"Up to file 2. X=(15000, 400) Y=(15000, 299, 299, 3).\n",
"Up to file 3. X=(20000, 400) Y=(20000, 299, 299, 3).\n",
"Shuffled\n",
"Up to file 0. X=(5000, 299, 299, 3) Y=(5000, 400).\n",
"Up to file 1. X=(10000, 299, 299, 3) Y=(10000, 400).\n",
"Up to file 2. X=(15000, 299, 299, 3) Y=(15000, 400).\n",
"Up to file 3. X=(20000, 299, 299, 3) Y=(20000, 400).\n",
"Up to file 4. X=(25000, 299, 299, 3) Y=(25000, 400).\n",
"Finish saving file\n"
]
}
],
"source": [
"PREFIX='../../video/'\n",
"FILES=['butterfly-ideal-20x20','travel-ideal-20x20','mario-ideal-20x20','drone-ideal-20x20']\n",
"OUTPUT_FILE='videos-ideal-20x20'\n",
"EXTENSION='.npz'\n",
"PREFIX='../'\n",
"FILES=['butterfly','travel','mario','nature','drone']\n",
"\n",
"SHUFFLE=True\n",
"OUTPUT_FILE='videos-ideal-20x20'\n",
"EXTENSION='-ideal-20x20.npz'\n",
"\n",
"SHUFFLE=False\n",
"CAP_SIZE=True\n",
"MAX_FRAMES=5000\n",
"\n",
"import numpy as np\n",
"\n",
......@@ -37,15 +39,23 @@
" fileNames.append(PREFIX+FILES[f]+EXTENSION)\n",
"\n",
"data=np.load(fileNames[0])\n",
"X=data['X'][:5000]\n",
"Y=data['Y'][:5000]\n",
"X=data['X']\n",
"Y=data['Y']\n",
"if CAP_SIZE:\n",
" X=X[:MAX_FRAMES]\n",
" Y=Y[:MAX_FRAMES]\n",
"\n",
"print(\"Up to file {}. X={} Y={}.\".format(0,X.shape,Y.shape))\n",
"\n",
"for f in range(1,len(fileNames)):\n",
" data=np.load(fileNames[f])\n",
" X=np.concatenate((X,data['X'][:5000]))\n",
" Y=np.concatenate((Y,data['Y'][:5000]))\n",
" \n",
" if CAP_SIZE:\n",
" X=np.concatenate((X,(data['X'])[:MAX_FRAMES]))\n",
" Y=np.concatenate((Y,(data['Y'])[:MAX_FRAMES]))\n",
" else:\n",
" X=np.concatenate((X,data['X']))\n",
" Y=np.concatenate((Y,data['Y']))\n",
" \n",
" print(\"Up to file {}. X={} Y={}.\".format(f,X.shape,Y.shape))\n",
"\n",
......
{
"cells": [
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"X shape (20000, 400) Y shape (20000, 299, 299, 3)\n"
]
},
{
"ename": "IndexError",
"evalue": "tuple index out of range",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mIndexError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-5-bdade1271f1e>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 49\u001b[0m \u001b[0mi\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mrandom\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrandint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mX\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mshape\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 50\u001b[0m \u001b[0;31m#print(i,Y[i],'\\r')\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 51\u001b[0;31m \u001b[0ml\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mgenImage\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mY\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 52\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 53\u001b[0m \u001b[0mcv2\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mimshow\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Image\"\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mX\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m<ipython-input-5-bdade1271f1e>\u001b[0m in \u001b[0;36mgenImage\u001b[0;34m(label)\u001b[0m\n\u001b[1;32m 32\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 33\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mgenImage\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlabel\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 34\u001b[0;31m \u001b[0mframe\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mzeros\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mshape\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mX\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mshape\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m3\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mdtype\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0muint8\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 35\u001b[0m \u001b[0mnoCellsSqrt\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmath\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msqrt\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlabel\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 36\u001b[0m \u001b[0mh\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mcellHeight\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mframe\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mshape\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m/\u001b[0m\u001b[0mnoCellsSqrt\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mIndexError\u001b[0m: tuple index out of range"
]
}
],
"source": [
"'''\n",
"This script is used to verify the dataset created\n",
"All you have to do is to change the FILE_NAME variable and run the program\n",
"\n",
"'''\n",
"\n",
"import numpy as np\n",
"import cv2\n",
"import sys\n",
"import random\n",
"import math\n",
"random.seed(625742)\n",
"FILE_NAME='../../../video/videos-ideal-20x20-shuffled.npz'\n",
"NO_FRAMES_TO_CHECK=100\n",
"SHELL=False\n",
"\n",
"\n",
"if SHELL:\n",
" if len(sys.argv)>=2:\n",
" FILE_NAME=sys.argv[1]\n",
" if len(sys.argv)==3:\n",
" NO_FRAMES_TO_CHECK=int(sys.argv[2])\n",
" \n",
" \n",
"\n",
"data=np.load(FILE_NAME)\n",
"X=data['X']\n",
"Y=data['Y']\n",
"\n",
"print(\"X shape\",X.shape,\"Y shape\",Y.shape)\n",
"\n",
"\n",
"def genImage(label):\n",
" frame=np.zeros((X.shape[1],X.shape[2],3),dtype=np.uint8)\n",
" noCellsSqrt=int(math.sqrt(len(label)))\n",
" h=cellHeight=int(frame.shape[0]/noCellsSqrt)\n",
" w=cellWidth=int(frame.shape[1]/noCellsSqrt)\n",
" for y in range(noCellsSqrt):\n",
" for x in range(noCellsSqrt):\n",
"# print(x,y,noCellsSqrt,h,w)\n",
" frame[y*h:(y+1)*h,x*w:(x+1)*w,:]=label[y*noCellsSqrt+x]*255\n",
" \n",
"# print(label[y*noCellsSqrt+x])\n",
" frame=cv2.flip(frame,-1)\n",
" return frame\n",
" \n",
"\n",
"for f in range(NO_FRAMES_TO_CHECK):\n",
" i=random.randint(0,X.shape[0]-1)\n",
" #print(i,Y[i],'\\r')\n",
" l=genImage(Y[i])\n",
"\n",
" cv2.imshow(\"Image\",X[i])\n",
" cv2.imshow(\"Label\",l)\n",
" cv2.waitKey(0)\n",
" \n",
"cv2.destroyAllWindows()\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"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.5.6"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
#!/usr/bin/env python
# coding: utf-8
# In[9]:
'''
This script is used to verify the dataset created
All you have to do is to change the FILE_NAME variable and run the program
'''
import numpy as np
import cv2
import sys
import random
import math
random.seed(625742)
FILE_NAME='../../video/nature-5x5.npz'
NO_FRAMES_TO_CHECK=100
SHELL=False
if SHELL:
if len(sys.argv)>=2:
FILE_NAME=sys.argv[1]
if len(sys.argv)==3:
NO_FRAMES_TO_CHECK=int(sys.argv[2])
data=np.load(FILE_NAME)
X=data['X']
Y=data['Y']
print("X shape",X.shape,"Y shape",Y.shape)
def genImage(label):
frame=np.zeros((X.shape[1],X.shape[2],3),dtype=np.uint8)
noCellsSqrt=int(math.sqrt(len(label)))
h=cellHeight=int(frame.shape[0]/noCellsSqrt)
w=cellWidth=int(frame.shape[1]/noCellsSqrt)
for y in range(noCellsSqrt):
for x in range(noCellsSqrt):
# print(x,y,noCellsSqrt,h,w)
frame[y*h:(y+1)*h,x*w:(x+1)*w,:]=label[y*noCellsSqrt+x]*255
# print(label[y*noCellsSqrt+x])
frame=cv2.flip(frame,-1)
return frame
for f in range(NO_FRAMES_TO_CHECK):
i=random.randint(0,X.shape[0]-1)
#print(i,Y[i],'\r')
l=genImage(Y[i])
cv2.imshow("Image",X[i])
cv2.imshow("Label",l)
cv2.waitKey(0)
cv2.destroyAllWindows()
# In[ ]:
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment