In this case, if you want to have a circular image, you must write a new algorithm, and first you must have access to the coordinates of the pixels .... then you can compare all the pixels that are not in the area of ββthe circle should get Null, then y you have everything you want! but I donβt know if opencv is null or not? so you can try it!
I am also writing this code and trying in some way, but I could not get the correct result! in this code, I create a rectangle around the circle and try to return pixels outside the circle!
import cv2 import numpy as np im = cv2.imread('sss.png') def facechop(im): height,width,depth = im.shape #circle = np.zeros((height,width)) #print circle x=width/2 y=height/2 circle=cv2.circle(im,(width/2,height/2),180,1,thickness=1) #newcameramtx, roi=cv2.getOptimalNewCameraMatrix(im,10,(w,h),1,(w,h)) cv2.rectangle(im,(x-180,y-180),(x+180,y+180),(0,0,255),2) crop_img = im[y-180:y+180,x-180:x+180] lastim=np.equal(crop_img,circle) #dd=np.logical_and(crop_img,circle) for i in range(len(last_im)) : if last_im[i].all()==False: crop_img[i]=[0,0,0] cv2.imshow('im',crop_img) if __name__ == '__main__': facechop(im) while(True): key = cv2.waitKey(20) if key in [27, ord('Q'), ord('q')]: break
Kasramvd
source share