def get_neg_samples(foldername, savePath): count = 0 imgs = [] labels = [] f = open('neg.txt') filenames = glob.iglob(os.path.join(foldername, '*')) for filename in filenames: print('filename = ', filename) src = cv.imread(filename, 1) if ((src.cols >= 64) & (src.rows >= 128)): x = random.uniform(0, src.cols - 64) y = random.uniform(0, src.rows - 128) imgRoi = src(cv.Rect(x, y, 64, 128)) imgs.append(imgRoi) saveName = savePath + 'neg' + str(count) + '.jpg' cv.imwrite(saveName, imgRoi) label = 'neg' + str(count) + '.jpg' labels.append(label) label = label + '\n' f.write(label) count += 1 return imgs, labels
def get_pos_samples(foldername, savePath): count = 0 imgs = [] labels = [] f = open('pos.txt') filenames = glob.iglob(os.path.join(foldername, '*')) for filename in filenames: print('filename = ', filename) src = cv.imread(filename) imgRoi = src(cv.Rect(16, 16, 64, 128)) imgs.append(imgRoi) saveName = savePath + 'neg' + str(count) + '.jpg' cv.imwrite(saveName, imgRoi) label = 'neg' + str(count) + '.jpg' labels.append(label) f.write(label) count += 1 return imgs, labels
import cv2 import sys import numpy as np import time import os img = cv2.imread(os.path.join('antImages', 'antpic_01.png'), 0) #this will import the image. # insert your image processing data here croppedFrame = img(cv2.Rect(0, img.rows / 2, img.cols, img.rows / 2)) cv2.imshow('image', img) #when you are ready you create a window to show the image. #this needs to have a title (that's the first argument) and the image itself cv2.waitKey( 0) #this part makes it so if any key is pressed, the window will close. #Convenience! Also sometimes opencv won't actually show the window unless you have this. cv2.destroyAllWindows() #just making sure everything's been cleaned up.