Skip to content

Instantly share code, notes, and snippets.

#SPECIFIC
def loadSeparateChannelInstanceLabelNoResize(labelPath, instances):
labelsInChannels = []
indexedImg = loadIndexedImage(labelPath)
for indx, inst in enumerate(instances):
labelsInChannels.append(getInstanceDataFromIndexedImage(indexedImg, int(inst)))
labelsInChannels = np.concatenate(labelsInChannels, axis=2)
if len(labelsInChannels.shape)<3:
labelsInChannels = np.expand_dims(labelsInChannels, axis=2)
return labelsInChannels
@fuankarion
fuankarion / 62-72.py
Last active November 12, 2018 18:22
Refactor 62-72
def getFirstFrrameInfo(video,videoInstances,videoFramesPerInstance):
firstFramesYT = None
firstFramesYTvideoLenghts = None
videoFirstFramesPerInstance = []
for inst in videoInstances[video]:
videoFirstFramesPerInstance.append(videoFramesPerInstance[video][inst][0])
videoFirstFramesPerInstance = sorted(list(set(videoFirstFramesPerInstance)))
firstFramesYT = videoFirstFramesPerInstance
firstFramesYTvideoLenghts= len(videoFirstFramesPerInstance)
ffmpeg -r 12 -i /home/jcleon/Storage/ssd0/DavisOLD/JPEGImages/480p/india/%05d.jpg -c:v libx264 -vf fps=25 -pix_fmt yuv420p india.mp4
def mat2Gray(matImg):
grayImage = np.zeros((matImg.shape), dtype=np.uint8)
cv2.normalize(matImg, grayImage, alpha=0, beta=255, norm_type=cv2.NORM_MINMAX, dtype=cv2.CV_8U)
return grayImage
@fuankarion
fuankarion / createCaffFCNLMDB.py
Created May 3, 2017 23:09
Create LMDB for Caffe FCN
import sys
caffeRoot='.../caffe/python'
sys.path.insert(0, caffeRoot)
import caffe
import lmdb
import glob
import numpy as np
from PIL import Image
import os
find . -name \*.jpg -print | while read line; do SIZE=$(identify -format '%wx%h' "$line"); echo "$SIZE -- $line"; done | sort -n -r
find . -name \*.jpg -print | while read line; do SIZE=$(identify -format '%wx%h' "$line"); echo "$SIZE -- $line"; done | awk '$1<239 || $2<239' | sort -n -r
import PIL.Image
from StringIO import StringIO
import lmdb
import numpy as np
import sys
caffe_root = '.../caffe/'
sys.path.insert(0, caffe_root + 'python')
import caffe #Caffe Lib
#Python code to use the PCAFlow by Wulff, input is a directory with images corresponding to the ordered video frames
import os
import sys
import cv2
import numpy as np
import re
dirPath = 'XXXXX/a68k87VXX1c'
targetPath='ZZZZZZ/temp'
resizeTarget=256
@fuankarion
fuankarion / ReadVideoFramesWithSkipPythonOpenCV.py
Last active September 15, 2017 15:18
Read Video frameskip Python
import cv2
#Read Video Frames From video With Skip Python OpenCV.
def getFramesFromVideo(videoPath,frameSkip):
print ('reading vid', videoPath)
cap = cv2.VideoCapture(videoPath)
print ('reading done ')
frames = []
print ('Loading frames to memory')
success, frame = cap.read()#get frame 0