Imgdb.py 文件源码

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

项目:osrmacro 作者: jjvilm 项目源码 文件源码
def turnBinary(self, img, *args):
        """Pass image as graysacle, else will be converted, other args include 'a' - add to DB, 'inv'-inverting, 's'-show"""
        #makes sure img is grayscale
        if len(img.shape) == 3:
            img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
        _,img = cv2.threshold(img, 254,255,cv2.THRESH_BINARY)
        print(img.shape)
        print("Turned Binary")
        try:
            for arg in args:
                # adds passed image to image db
                if arg == 'a':
                    img_name = raw_input("Name for image\n")
                    self.pickled_dict[img_name] = img
                    self.savePickledDict()
                # inverts binary img
                if arg == 'inv':
                    img_name = raw_input("Name for image\n")
                    _, img = cv2.threshold(img,0,255,cv2.THRESH_BINARY_INV)
                # shows img
                if arg == "s":
                    cv2.imshow('img',img)
                    cv2.waitKey(0)
        except:
            pass
        return img
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号