Tshirt.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:virtual-dressing-room 作者: akash0x53 项目源码 文件源码
def detect_shirt2(self):
        self.hsv=cv2.cvtColor(self.norm_rgb,cv.CV_BGR2HSV)
        self.hue,s,_=cv2.split(self.hsv)

        _,self.dst=cv2.threshold(self.hue,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)
        self.fg=cv2.erode(self.dst,None,iterations=3)
        self.bg=cv2.dilate(self.dst,None,iterations=1)
        _,self.bg=cv2.threshold(self.bg,1,128,1)
        mark=cv2.add(self.fg,self.bg)
        mark32=np.int32(mark)
        cv2.watershed(self.norm_rgb,mark32)

        m=cv2.convertScaleAbs(mark32)
        _,m=cv2.threshold(m,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)

        cntr,h=cv2.findContours(m,cv.CV_RETR_EXTERNAL,cv.CV_CHAIN_APPROX_SIMPLE)
        print len(cntr)
        #print cntr[0].shape
        #cntr[1].dtype=np.float32
        #ret=cv2.contourArea(np.array(cntr[1]))
        #print ret
        #cntr[0].dtype=np.uint8
        cv2.drawContours(m,cntr,-1,(255,255,255),3)
        cv2.imshow("mask_fg",self.fg)
        cv2.imshow("mask_bg",self.bg)
        cv2.imshow("mark",m)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号