Exemplo n.º 1
0
def compareWithGroundtruth(sal,datasetPath,imageName):
	print "Processing "+imageName +" ....";
	confusion = getNewConfusion();
	srcImgPath = os.path.join(datasetPath,imageName,"src_color",imageName+".png")
	image = cv2.imread(srcImgPath)
	mask = getSalienyMap(sal,image)
	
	#write results
	mask_image = image*mask[:,:,None];
	mkdirs(os.path.join(datasetPath,imageName,"results"));
	file_name = os.path.join(datasetPath,imageName,"results",imageName+"_"+sal.method+".png")
	cv2.imwrite(file_name,mask_image)
	
	humanSegPath = os.path.join(datasetPath,imageName,"human_seg");
	for bgImg in os.listdir(humanSegPath):
		if bgImg.endswith(".png"):
			bgMask = getMask(cv2.imread(os.path.join(humanSegPath,bgImg)))
			updateConfusion(confusion,comparator(bgMask,mask))
	print "Confusion : ",confusion;
	return confusion;	
Exemplo n.º 2
0
def compareWithGroundtruth(sal, datasetPath, imageName):
    print "Processing " + imageName + " ...."
    confusion = getNewConfusion()
    srcImgPath = os.path.join(datasetPath, imageName, "src_color",
                              imageName + ".png")
    image = cv2.imread(srcImgPath)
    mask = getSalienyMap(sal, image)

    #write results
    mask_image = image * mask[:, :, None]
    mkdirs(os.path.join(datasetPath, imageName, "results"))
    file_name = os.path.join(datasetPath, imageName, "results",
                             imageName + "_" + sal.method + ".png")
    cv2.imwrite(file_name, mask_image)

    humanSegPath = os.path.join(datasetPath, imageName, "human_seg")
    for bgImg in os.listdir(humanSegPath):
        if bgImg.endswith(".png"):
            bgMask = getMask(cv2.imread(os.path.join(humanSegPath, bgImg)))
            updateConfusion(confusion, comparator(bgMask, mask))
    print "Confusion : ", confusion
    return confusion
def perform_localization(vidreader,roi_mask,smoothner,fgMasks,bgMasks,gtMasks,
							num_blocks=10,skip_frames = 0,last_frame=1000):
	confusion = getNewConfusion();
	start = time.time();	frameNewMasks = []; 
	frame_idx = skip_frames + 2*num_blocks;  N = min(vidreader.frames,last_frame);
	status = 'Localizing Video ' + vidreader.foldername  +' ... {0}\r'
	out_dir=os.path.dirname(vidreader.foldername)+os.sep+'output'+os.sep
	create_folder_structure_if_not_exists(out_dir);
	while(frame_idx +num_blocks  < N):
		print status.format((str(frame_idx*100/N)+'%')),
		(num_frames,frames) = vidreader.read(frame_idx-2*num_blocks,2*num_blocks);
		if num_frames > num_blocks:
			start_idx = num_blocks/2; end_idx = min(3*num_blocks/2,num_frames);
			s = frame_idx-2*num_blocks-skip_frames; e = s + num_frames;
			newMasks = smoothner.process(frames,fgMasks[s:e],bgMasks[s:e],range(start_idx,end_idx));
			#newMasks = __morphologicalOps__(newMasks);
			groundTruthMasks = gtMasks[s+num_blocks/2:s+num_blocks/2+newMasks.__len__()];	
			_frames = frames[num_blocks/2:num_blocks/2+newMasks.__len__()];
			tmp_idx= 0;
			for (gt,my) in zip(groundTruthMasks,newMasks):
				zero = np.zeros(gt.shape[:2],dtype=np.uint8)
				my_mask = np.uint8(np.dstack((zero,zero,my*255)))
				out = cv2.addWeighted(_frames[tmp_idx],0.6,my_mask,0.4,0);
				path = out_dir+os.sep+'sal_'+str(frame_idx-2*num_blocks-skip_frames+tmp_idx)+'.png'
				cv2.imwrite(path,out)
				gt_mask = np.uint8(np.dstack((zero,zero,gt*255)));
				out = cv2.addWeighted(_frames[tmp_idx],0.6,gt_mask,0.4,0);
				path = out_dir+os.sep+'gt_'+str(frame_idx-2*num_blocks-skip_frames+tmp_idx)+'.png'
				cv2.imwrite(path,out)
				frame_confusion=comparator(gt,my,roi_mask);
				updateConfusion(confusion,frame_confusion);
				tmp_idx += 1
			
		frame_idx += num_blocks
	time_taken = time.time()-start;	
	print status.format('[Done] in '),time_taken," seconds"
	return confusion;