Esempio n. 1
0
def makeunsuperviseAA(dataroot,ABpath,batchflag):
	oriimagelist=os.listdir(dataroot)
	i=0
	for o in oriimagelist:
		oroot_image=os.path.join(dataroot,o)
		F=getface(oroot_image)
		if F is None:
			continue

		inputimage=getrectimage(cv2.imread(oroot_image),F[0],F[1],F[2],F[3])



		rgbImg = cv2.cvtColor(inputimage, cv2.COLOR_BGR2RGB)
		landmark=get_landmark(rgbImg)
		if landmark is None:
			continue
		mask=getContourStat(landmark,inputimage)

		input_maskimage=getmaskimage(inputimage,mask)
		#cv2.imshow('input',input_maskimage)
		#cv2.waitKey(0)


		inputnew=os.path.join(ABpath,batchflag+str(i)+'.jpg')
		im_AB = np.concatenate([input_maskimage, input_maskimage], 1)
		print im_AB.shape
		cv2.imwrite(inputnew, im_AB)
		i+=1
Esempio n. 2
0
def writelightlist(dataroot,origin_dataroot,Apath,batchflag):
	oriimagelist=os.listdir(origin_dataroot)
	i=0
	for o in oriimagelist:
		troot=os.path.join(dataroot,os.path.splitext(o)[0])
		oroot_image=os.path.join(origin_dataroot,o)
		F=getface(oroot_image)
		if F is None:
			continue

		inputimage=getrectimage(cv2.imread(oroot_image),F[0],F[1],F[2],F[3])



		rgbImg = cv2.cvtColor(inputimage, cv2.COLOR_BGR2RGB)
		landmark=get_landmark(rgbImg)
		if landmark is None:
			continue
		mask=getContourStat(landmark,inputimage)


		input_maskimage=getmaskimage(inputimage,mask)
		#cv2.imshow('input',input_maskimage)
		#cv2.waitKey(0)

		for root, dirs, files in os.walk(troot, topdown=False):

			for troot_image in files:
				if os.path.splitext(troot_image)[1]!='.jpg':
					continue

				troot_image=os.path.join(root, troot_image)

				outputimage=getrectimage(cv2.imread(troot_image),F[0],F[1],F[2],F[3])
				output_maskimage=getmaskimage(outputimage,mask)


				inputnew=os.path.join(Apath,batchflag+str(i)+'.jpg')

				im_AB = np.concatenate([output_maskimage, input_maskimage], 1)
				cv2.imwrite(inputnew, im_AB)
				#cv2.imwrite(inputnew,output_maskimage)
				#cv2.imwrite(outputnew,input_maskimage)
				i+=1
Esempio n. 3
0
def stdcrop(dataroot):

	imgs=os.listdir(dataroot)
	for i in imgs:
		path=dataroot+'/'+i
		F=getface(path)
		if F is None:
			continue
		out=getrectimage(cv2.imread(path),F[0],F[1],F[2],F[3])
		cv2.imwrite(path,out)
Esempio n. 4
0
def makelist(dataroot="../ExtendedYaleB"):
	A=os.listdir(dataroot)
	files=[]
	for f in A:
		f=dataroot+'/'+f
		pgm=os.listdir(f)
		for p in pgm:
			if 'info' in p:
				files.append(f+'/'+p)
	random.shuffle(files)
	c=100000
	for f in files:
		basedir=os.path.dirname(f)
		lines=[]
		with open(f) as fl:
			for i,l in enumerate(fl.readlines()):
				if i==0:
					continue
				lines.append(l.split()[0])
		for l in lines[1:]:
			src=basedir+'/'+lines[0]
			tar=basedir+'/'+l
			srcimg = read_pgm(src, byteorder='<')
			tarimg = read_pgm(tar, byteorder='<')
			oroot='../light_for_train/B/'+str(c)+'.jpg'
			troot='../light_for_train/A/'+str(c)+'.jpg'
			cv2.imwrite(troot,tarimg)
			cv2.imwrite(oroot,srcimg)





			F=getface(oroot)
			if F is None:
				continue
			out=getrectimage(cv2.imread(oroot),F[0],F[1],F[2],F[3])
			cv2.imwrite(oroot,out)
			out=getrectimage(cv2.imread(troot),F[0],F[1],F[2],F[3])
			cv2.imwrite(troot,out)
			c+=1

			print oroot
Esempio n. 5
0
def maskinput_image(origin_image_root,size):
	F=getface(oroot_imageA)
	if F is None:
		return None
	inputimage=getrectimage(cv2.imread(oroot_image),F[0],F[1],F[2],F[3])
	rgbImg = cv2.cvtColor(inputimage, cv2.COLOR_BGR2RGB)
	landmark=get_landmark(rgbImg)
	if landmark is None:
		return None
	mask=getContourStat(landmark,inputimage)
	input_maskimage=getmaskimage(inputimage,mask)

	input_maskimage=cv2.resize(input_maskimage,(300,300))
	return input_maskimage
Esempio n. 6
0
def mask_crop(imagepaths):
    ori_imagepath = imagepaths[0]
    tar_imagepath = imagepaths[1]

    BF = getface(ori_imagepath)
    if BF is None:
        return
    Bimage = getrectimage(cv2.imread(ori_imagepath), BF[0], BF[1], BF[2],
                          BF[3])
    BrgbImg = cv2.cvtColor(Bimage, cv2.COLOR_BGR2RGB)
    Blandmark = get_landmark(BrgbImg)
    if Blandmark is None:
        return
    Bmask = getContourStat(Blandmark, Bimage)
    Bimage = getmaskimage(Bimage, Bmask)
    cv2.imwrite(tar_imagepath, Bimage)
Esempio n. 7
0
def writelightlist(tar_dataroot, origin_dataroot, ABpath, batchflag):
    if os.path.exists(ABpath) is False:
        os.makedirs(ABpath)

    process_crop(tar_dataroot, ABpath)
    oriimagelist = os.listdir(origin_dataroot)
    tarimagelist = os.listdir(ABpath)

    for o in oriimagelist:
        oroot_image = os.path.join(origin_dataroot, o)
        BF = getface(oroot_image)
        if BF is None:
            continue
        Bimage = getrectimage(cv2.imread(oroot_image), BF[0], BF[1], BF[2],
                              BF[3])
        BrgbImg = cv2.cvtColor(Bimage, cv2.COLOR_BGR2RGB)
        Blandmark = get_landmark(BrgbImg)
        if Blandmark is None:
            continue
        Bmask = getContourStat(Blandmark, Bimage)

        Bimage = getmaskimage(Bimage, Bmask)

        Bimage = cv2.resize(Bimage, (300, 300))

        fileo = int(o[7:-4])

        for tarf in tarimagelist:
            filet = int(tarf.split('.')[0])
            if filet != fileo:
                continue
            Aimage = cv2.imread(os.path.join(ABpath, tarf))
            Aimage = cv2.resize(Aimage, (300, 300))

            im_AB = np.concatenate([Aimage, Bimage], 1)
            cv2.imwrite(os.path.join(ABpath, tarf), im_AB)