def testRestart(self): fitness = FitnessNapsack() ilog = pv.ImageLog() restart_dir = ilog.dir #fitness.solve() alg = ga.GeneticAlgorithm(fitness,[ga.GARanking(100)],n_processes=1) result = alg.optimize(max_iter=500,ilog=ilog) time.sleep(2) #print "Restarting..." ilog = pv.ImageLog() alg = ga.GeneticAlgorithm(fitness,[ga.GARanking(100)],n_processes=1) result = alg.optimize(max_iter=1000,ilog=ilog,restart_dir=restart_dir)
def test01_hsHist(self): '''Test hue saturation histogram.''' ilog = pv.ImageLog() im = pv.Image( os.path.join(pv.__path__[0], "data", "misc", "baboon.jpg")) mask = np.zeros((512, 512), dtype=np.bool) mask[150:200, 128:300] = True m = pv.Image(1.0 * mask) ilog(im) ilog(m) hist = hsHist(im, mask=m) print hist print dir(hist) #print dir(hist.bins),hist.bins.channels #for i in range(32): # for j in range(30): # print i,j,cv.QueryHistValue_2D(hist,j,i) hist.rescaleMax(255) print hist.asMatrix() #print cv.SetHistBinRanges back = hist.backProject(im) ilog(back) ilog.show()
def testBugsVideo(self): ilog = pv.ImageLog() #ilog = None video = pv.FFMPEGVideo(BUGS_VIDEO) i = 0 for frame in video: if ilog != None: print "Processing Frame:", i #if frame != None: ilog(frame, format='jpg') i += 1 if ilog != None: ilog.show()
tmp4.annotateLabel(pv.Point(10, 10), "ScaleTest: use_orig=True") tmp4.annotateLabel(pv.Point(20, 20), "This image should be sharp.") ilog.log(tmp4) # Now remove the reverence to the im instance. The weak references within # tmp1 do not hold onto the original data so now there is no choice but to # use the scaled down image. del im tmp5 = aff_big.transformImage(tmp1, use_orig=True) tmp5.annotateLabel(pv.Point(10, 10), "ScaleTest: use_orig=True") tmp5.annotateLabel(pv.Point(20, 20), "This image should be blurry") tmp5.annotateLabel(pv.Point(20, 30), "because the original has be") tmp5.annotateLabel(pv.Point(20, 40), "removed from memory.") ilog.log(tmp5) # Weak references are used to prevent python from hanging onto larger images # when the user deletes there references or they go out of scope. To # use the original images further down the image pipeline make sure that # they are expressly kept around. This feature is designed as a convenience # so that the user does not have to keep track of many affine transforms and # images, and can accumulate transforms as if each one goes all the way back # to the original image if it is still available. It also does not interfere # memory management if the user decides to drop references to large images. if __name__ == '__main__': ilog = pv.ImageLog() Example1(ilog) ilog.show()
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import pyvision as pv from pyvision.edge.canny import canny # An interface to the OpenCV Canny. ''' This code is from part 1 of the PyVision Quick Start Guide. ''' if __name__ == '__main__': # (1) Load an image from a file. im = pv.Image(pv.__path__[0] + "/data/nonface/NONFACE_16.jpg") # (2) Rescale the image im = pv.AffineScale(0.5, (320, 240)).transformImage(im) # (3) Run the canny function to locate the edges. edge_im1 = canny(im) # (4) Run the canny function with different defaults. edge_im2 = canny(im, threshold1=100, threshold2=250) # (5) Save the results to a log. ilog = pv.ImageLog("../..") ilog.log(im, label="Source") ilog.log(edge_im1, label="Canny1") ilog.log(edge_im2, label="Canny2") # (6) Display the results. ilog.show()
# If an integer is passed to the sample option then subselect the image names. if options.sample != None: image_names = random.sample(image_names,options.sample) # Open the file to use as output. f = open(args[1],'wb') csv_file = csv.writer(f) headers = ['image_name','detect_number','detect_x','detect_y','detect_width','detect_height','eye1_x','eye1_y','eye2_x','eye2_y'] csv_file.writerow(headers) # Create an image log if this is being saved to a file. ilog = None if options.log_dir != None: print("Creating Image Log...") ilog = pv.ImageLog(options.log_dir) # For each image run face and eye detection face_detect = CascadeDetector(image_scale=1.3*options.scale) locate_eyes = FilterEyeLocator()#locator_filename) c = 0 for pathname in image_names: c += 1 im = pv.Image(pathname) scale = options.log_scale log_im = pv.AffineScale(scale,(int(scale*im.width),int(scale*im.height))).transformImage(im)