예제 #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
예제 #2
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
예제 #3
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)
예제 #4
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
예제 #5
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)