comparison scripts/extract-appearance-images.py @ 905:0e017178f7ab

correct bug in classify-objects script when correcting for distrotion
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Thu, 22 Jun 2017 23:40:16 -0400
parents 8f60ecfc2f06
children a57e6fbcd8e3
comparison
equal deleted inserted replaced
904:8f60ecfc2f06 905:0e017178f7ab
1 #! /usr/bin/env python 1 #! /usr/bin/env python
2 2
3 import numpy as np, cv2 3 import numpy as np, cv2
4 import argparse, os 4 import argparse, os
5 from pandas import read_csv 5 from pandas import read_csv
6 from matplotlib.pyplot import imsave 6 from matplotlib.pyplot import imsave, imshow, figure
7 7
8 import cvutils, moving, ml, storage 8 import cvutils, moving, ml, storage
9 9
10 parser = argparse.ArgumentParser(description='The program extracts labeled image patches to train the HoG-SVM classifier, and optionnally speed information') 10 parser = argparse.ArgumentParser(description='The program extracts labeled image patches to train the HoG-SVM classifier, and optionnally speed information')
11 parser.add_argument('--cfg', dest = 'configFilename', help = 'name of the configuration file', required = True) 11 parser.add_argument('--cfg', dest = 'configFilename', help = 'name of the configuration file', required = True)
51 width = int(capture.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH)) 51 width = int(capture.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH))
52 height = int(capture.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT)) 52 height = int(capture.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT))
53 53
54 if undistort: # setup undistortion 54 if undistort: # setup undistortion
55 [map1, map2] = cvutils.computeUndistortMaps(width, height, undistortedImageMultiplication, intrinsicCameraMatrix, distortionCoefficients) 55 [map1, map2] = cvutils.computeUndistortMaps(width, height, undistortedImageMultiplication, intrinsicCameraMatrix, distortionCoefficients)
56 height, width = map1.shape
56 57
57 print(timeInterval) 58 print(timeInterval)
58 if capture.isOpened(): 59 if capture.isOpened():
59 ret = True 60 ret = True
60 frameNum = timeInterval.first 61 frameNum = timeInterval.first
67 print('frame number: {}'.format(frameNum)) 68 print('frame number: {}'.format(frameNum))
68 if undistort: # undistort only if necessary 69 if undistort: # undistort only if necessary
69 img = cv2.remap(img, map1, map2, interpolation=cv2.INTER_LINEAR) 70 img = cv2.remap(img, map1, map2, interpolation=cv2.INTER_LINEAR)
70 for obj in objects: 71 for obj in objects:
71 if obj.existsAtInstant(frameNum): 72 if obj.existsAtInstant(frameNum):
72 if (obj.getFirstInstant()-frameNum)%args.nFramesStep == 0: # todo find next non zero image if none 73 if (10+frameNum-obj.getFirstInstant())%args.nFramesStep == 0: # todo find next non zero image if none
73 croppedImg = cvutils.imageBox(img, obj, frameNum, invHomography, width, height, classifierParams.percentIncreaseCrop, classifierParams.percentIncreaseCrop, classifierParams.minNPixels) 74 croppedImg = cvutils.imageBox(img, obj, frameNum, invHomography, width, height, classifierParams.percentIncreaseCrop, classifierParams.percentIncreaseCrop, classifierParams.minNPixels)
74 if croppedImg is not None: 75 if croppedImg is not None:
75 imsave(args.directoryName+os.sep+moving.userTypeNames[obj.getUserType()]+args.imagePrefix+'-{}-{}.png'.format(obj.getNum(), frameNum), croppedImg) 76 imsave(args.directoryName+os.sep+moving.userTypeNames[obj.getUserType()]+os.sep+args.imagePrefix+'-{}-{}.png'.format(obj.getNum(), frameNum), croppedImg)
76 elif obj.getLastInstant() == frameNum: 77 elif obj.getLastInstant() == frameNum:
77 objects.remove(obj) 78 objects.remove(obj)
78 frameNum += 1 79 frameNum += 1
79 80
80 # todo speed info: distributions AND min speed equiprobable 81 # todo speed info: distributions AND min speed equiprobable