Beispiel #1
0
import os # Operating System 
import sys

import isak

isak.validateArgvMsg("<directory> <dat file>", 3)	

directory = str(sys.argv[1])
samp_dir = os.fsencode(directory)

dat_file = open(str(sys.argv[2]), "w")

for im_file in os.listdir(samp_dir) :
	im_name = directory + "\\" + os.fsdecode(im_file)
	dat_file.write(im_name + " 1 0 0 20 20\n")

dat_file.close()
import os
import cv2
import numpy as np 
import re
import sys 

import isak # my own library of useful functions

isak.validateArgvMsg("<image directory> <roi file name>", 3)

im_dir_name = str(sys.argv[1])
roi_file = open( str(sys.argv[2]) )
im_dir = os.fsencode(im_dir_name)

for file in os.listdir(im_dir) :
	
	file_name = os.fsdecode(file)
	im = cv2.imread(im_dir_name + "\\" + file_name)

	for roi in isak.getROIs(roi_file) :
		roi = tuple(abs(r) for r in roi)
		cropped = isak.cropImage(im, roi)
		(h, w, c) = cropped.shape
		sf = 1200.0/(max(w,h))
		cropped = cv2.resize(cropped, (0,0), fx=sf, fy=sf, interpolation = cv2.INTER_NEAREST)
		
		# Graphical information
	
		isak.drawText(cropped, str(w) + " x " + str(h))
		isak.drawCrosshair(cropped)
import os
import cv2
import numpy as np
import re
import sys

import isak

isak.validateArgvMsg("<image directory> <input rois> <output rois>", 4)

samples_dir_name = str(sys.argv[1])
old_rois = str(sys.argv[2])
new_rois = str(sys.argv[3])

beta_rois_file = open(new_rois, "w")
rois_file = open(old_rois, "r")
samples_dir = os.fsencode(samples_dir_name)

files = os.listdir(samples_dir)
num_images = len(files)
img_ctr = 1

for file in files:

    file_name = os.fsdecode(file)
    im = cv2.imread(samples_dir_name + "\\" + file_name)

    beta_rois_file.write(file_name + " : ")
    ctr = 0
    for roi in isak.getROIs(rois_file):
Beispiel #4
0
import os
import cv2
import numpy as np 
import sys

import isak

isak.validateArgvMsg("<samples directory>", 2)

samples_dir_name = str(sys.argv[1])
samples_dir = os.fsencode(samples_dir_name)


files = os.listdir(samples_dir)
num_files = len(files)

ctr = 0 
for file in files :
	file_name = os.fsdecode(file)
	im = cv2.imread(samples_dir_name + "\\" + file_name)
	
	sf = 16.0
	im = cv2.resize(im, (0,0), fx=sf, fy=sf, interpolation = cv2.INTER_NEAREST)

	isak.drawText(im, str(ctr) + "/" + str(num_files) ) 
	cv2.imshow("test", im)

	key = cv2.waitKey()
	if (key == ord('x')) : # then delete that sample
		os.remove(samples_dir_name + "\\" + file_name)
    g_filt = g / grayscale
    g_filt = unitAdjust(g_filt)
    g_filt *= g_filt

    # out
    out = r_filt - b_filt - g_filt + 2.0
    out = unitAdjust(out)
    out *= out
    # out *= out
    # out *= out
    # out = r
    out = 255.0 * out
    return out.astype(np.uint8)


isak.validateArgvMsg("<cascade xml file> <name of image directory>", 3)

cascade_xml = str(sys.argv[1])
img_dir_name = str(sys.argv[2])

img_dir = os.fsencode(img_dir_name)

for img_file in os.listdir(img_dir):

    file_name = os.fsdecode(img_file)
    img = cv2.imread(img_dir_name + "\\" + file_name)
    gray = preprocess(img)

    cascade = cv2.CascadeClassifier(cascade_xml)
    centers = myDetect(gray, cascade)
    rects = detect(gray, cascade)