当前位置: 首页>>代码示例>>Python>>正文


Python cv2.__version__方法代码示例

本文整理汇总了Python中cv2.__version__方法的典型用法代码示例。如果您正苦于以下问题:Python cv2.__version__方法的具体用法?Python cv2.__version__怎么用?Python cv2.__version__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cv2的用法示例。


在下文中一共展示了cv2.__version__方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_opencv

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import __version__ [as 别名]
def test_opencv():
    """
    This function is workaround to 
    test if correct OpenCV Library version has already been installed
    on the machine or not. Returns True if previously not installed.
    """
    try:
        # import OpenCV Binaries
        import cv2

        # check whether OpenCV Binaries are 3.x+
        if parse_version(cv2.__version__) < parse_version("3"):
            raise ImportError(
                "Incompatible (< 3.0) OpenCV version-{} Installation found on this machine!".format(
                    parse_version(cv2.__version__)
                )
            )
    except ImportError:
        return True
    return False 
开发者ID:abhiTronix,项目名称:vidgear,代码行数:22,代码来源:setup.py

示例2: check6_bsddb3

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import __version__ [as 别名]
def check6_bsddb3(self):
        '''bsddb3 - Python Bindings for Oracle Berkeley DB

        requires Berkeley DB

        PY_BSDDB3_VER_MIN = (6, 0, 1) # 6.x series at least
        '''
        self.append_text("\n")
        # Start check

        try:
            import bsddb3 as bsddb
            bsddb_str = bsddb.__version__  # Python adaptation layer
            # Underlying DB library
            bsddb_db_str = str(bsddb.db.version()).replace(', ', '.')\
                .replace('(', '').replace(')', '')
        except ImportError:
            bsddb_str = 'not found'
            bsddb_db_str = 'not found'

        result = ("* Berkeley Database library (bsddb3: " + bsddb_db_str +
                  ") (Python-bsddb3 : " + bsddb_str + ")")
        # End check
        self.append_text(result) 
开发者ID:gramps-project,项目名称:addons-source,代码行数:26,代码来源:PrerequisitesCheckerGramplet.py

示例3: check_fontconfig

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import __version__ [as 别名]
def check_fontconfig(self):
        ''' The python-fontconfig library is used to support the Genealogical
        Symbols tab of the Preferences.  Without it Genealogical Symbols don't
        work '''
        try:
            import fontconfig
            vers = fontconfig.__version__
            if vers.startswith("0.5."):
                result = ("* python-fontconfig " + vers +
                          " (Success version 0.5.x is installed.)")
            else:
                result = ("* python-fontconfig " + vers +
                          " (Requires version 0.5.x)")
        except ImportError:
            result = "* python-fontconfig Not found, (Requires version 0.5.x)"
        # End check
        self.append_text(result)

    #Optional 
开发者ID:gramps-project,项目名称:addons-source,代码行数:21,代码来源:PrerequisitesCheckerGramplet.py

示例4: check23_pedigreechart

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import __version__ [as 别名]
def check23_pedigreechart(self):
        '''PedigreeChart - Can optionally use - NumPy if installed

        https://github.com/gramps-project/addons-source/blob/master/PedigreeChart/PedigreeChart.py
        '''
        self.append_text("\n")
        self.render_text("""<b>03. <a href="https://gramps-project.org/wiki"""
                         """/index.php?title=PedigreeChart">"""
                         """Addon:PedigreeChart</a> :</b> """)
        # Start check

        try:
            import numpy
            numpy_ver = str(numpy.__version__)
            #print("numpy.__version__ :" + numpy_ver )
            # NUMPY_check = True
        except ImportError:
            numpy_ver = "Not found"
            # NUMPY_check = False

        result = "(NumPy : " + numpy_ver + " )"
        # End check
        self.append_text(result)
        #self.append_text("\n") 
开发者ID:gramps-project,项目名称:addons-source,代码行数:26,代码来源:PrerequisitesCheckerGramplet.py

示例5: detectAndDescribe

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import __version__ [as 别名]
def detectAndDescribe(self, image):
        # check to see if we are using OpenCV 3.X
        if int(cv2.__version__[0]) >= 3:
            # detect and extract features from the image
            descriptor = cv2.xfeatures2d.SIFT_create()
            (kps, features) = descriptor.detectAndCompute(image, None)

        # otherwise, we are using OpenCV 2.4.X
        else:
            # convert the image to grayscale
            gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

            # detect keypoints in the image
            detector = cv2.FeatureDetector_create("SIFT")
            kps = detector.detect(gray)

            # extract features from the image
            extractor = cv2.DescriptorExtractor_create("SIFT")
            (kps, features) = extractor.compute(gray, kps)

        # convert the keypoints from KeyPoint objects to NumPy arrays
        kps = np.float32([kp.pt for kp in kps])

        # return a tuple of keypoints and features
        return (kps, features) 
开发者ID:cynricfu,项目名称:dual-fisheye-video-stitching,代码行数:27,代码来源:stitcher.py

示例6: _mask_post_processing

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import __version__ [as 别名]
def _mask_post_processing(mask, center_pos, size, track_mask_threshold):
    target_mask = (mask > track_mask_threshold)
    target_mask = target_mask.astype(np.uint8)
    if cv2.__version__[-5] == '4':
        contours, _ = cv2.findContours(target_mask,
                                       cv2.RETR_EXTERNAL,
                                       cv2.CHAIN_APPROX_NONE)
    else:
        _, contours, _ = cv2.findContours(
                target_mask,
                cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
    cnt_area = [cv2.contourArea(cnt) for cnt in contours]
    if len(contours) != 0 and np.max(cnt_area) > 100:
        contour = contours[np.argmax(cnt_area)] 
        polygon = contour.reshape(-1, 2)
        prbox = cv2.boxPoints(cv2.minAreaRect(polygon))
        rbox_in_img = prbox
    else:  # empty mask
        location = cxy_wh_2_rect(center_pos, size)
        rbox_in_img = np.array([[location[0], location[1]],
                    [location[0] + location[2], location[1]],
                    [location[0] + location[2], location[1] + location[3]],
                    [location[0], location[1] + location[3]]])
    return rbox_in_img 
开发者ID:chainer,项目名称:models,代码行数:26,代码来源:siam_mask_tracker.py

示例7: draw_result

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import __version__ [as 别名]
def draw_result(self, img, result):   #输出结果
        print("hell")
        print(len(result))
        for i in range(len(result)):
            x = int(result[i][1])
            y = int(result[i][2])
            w = int(result[i][3] / 2)
            h = int(result[i][4] / 2)
            cv2.rectangle(img, (x - w, y - h), (x + w, y + h), (0, 255, 0), 2)
            cv2.rectangle(img, (x - w, y - h - 20),
                          (x + w, y - h), (125, 125, 125), -1)
            lineType = cv2.LINE_AA if cv2.__version__ > '3' else cv2.CV_AA
            cv2.putText(
                img, result[i][0] + ' : %.2f' % result[i][5],
                (x - w + 5, y - h - 7), cv2.FONT_HERSHEY_SIMPLEX, 0.5,
                (0, 0, 0), 1, lineType) 
开发者ID:TowardsNorth,项目名称:yolo_v1_tensorflow_guiyu,代码行数:18,代码来源:test.py

示例8: _mask_post_processing

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import __version__ [as 别名]
def _mask_post_processing(self, mask):
        target_mask = (mask > cfg.TRACK.MASK_THERSHOLD)
        target_mask = target_mask.astype(np.uint8)
        if cv2.__version__[-5] == '4':
            contours, _ = cv2.findContours(target_mask,
                                           cv2.RETR_EXTERNAL,
                                           cv2.CHAIN_APPROX_NONE)
        else:
            _, contours, _ = cv2.findContours(target_mask,
                                              cv2.RETR_EXTERNAL,
                                              cv2.CHAIN_APPROX_NONE)
        cnt_area = [cv2.contourArea(cnt) for cnt in contours]
        if len(contours) != 0 and np.max(cnt_area) > 100:
            contour = contours[np.argmax(cnt_area)]
            polygon = contour.reshape(-1, 2)
            prbox = cv2.boxPoints(cv2.minAreaRect(polygon))
            rbox_in_img = prbox
        else:  # empty mask
            location = cxy_wh_2_rect(self.center_pos, self.size)
            rbox_in_img = np.array([[location[0], location[1]],
                                    [location[0] + location[2], location[1]],
                                    [location[0] + location[2], location[1] + location[3]],
                                    [location[0], location[1] + location[3]]])
        return rbox_in_img 
开发者ID:STVIR,项目名称:pysot,代码行数:26,代码来源:siammask_tracker.py

示例9: test_matchSIFTKeyPoints

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import __version__ [as 别名]
def test_matchSIFTKeyPoints():
    try:
        import cv2
    except ImportError:
        pass
        return
    if not "2.4.3" in cv2.__version__:
        pass
        return
    img = Image("lenna")
    skp, tkp =  img.matchSIFTKeyPoints(img)
    if len(skp) == len(tkp):
        for i in range(len(skp)):
            if (skp[i].x == tkp[i].x and skp[i].y == tkp[i].y):
                pass
            else:
                assert False
    else:
        assert False 
开发者ID:sightmachine,项目名称:SimpleCV2,代码行数:21,代码来源:tests.py

示例10: test_getFREAKDescriptor

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import __version__ [as 别名]
def test_getFREAKDescriptor():
    try:
        import cv2
    except ImportError:
        pass
    if '$Rev' in cv2.__version__:
        pass
    else:
        if int(cv2.__version__.replace('.','0'))>=20402:
            img = Image("lenna")
            flavors = ["SIFT", "SURF", "BRISK", "ORB", "STAR", "MSER", "FAST", "Dense"]
            for flavor in flavors:
                f, d = img.getFREAKDescriptor(flavor)
                if len(f) == 0:
                    assert False
                if d.shape[0] != len(f) and d.shape[1] != 64:
                    assert False
        else:
            pass
    pass 
开发者ID:sightmachine,项目名称:SimpleCV2,代码行数:22,代码来源:tests.py

示例11: main

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import __version__ [as 别名]
def main():
    print('OpenCV version {} '.format(cv2.__version__))

    current_dir = os.path.dirname(__file__)

    author = '021'
    training_folder = os.path.join(current_dir, 'data/training/', author)
    test_folder = os.path.join(current_dir, 'data/test/', author)

    training_data = []
    for filename in os.listdir(training_folder):
        img = cv2.imread(os.path.join(training_folder, filename), 0)
        if img is not None:
            data = np.array(preprocessor.prepare(img))
            data = np.reshape(data, (901, 1))
            result = [[0], [1]] if "genuine" in filename else [[1], [0]]
            result = np.array(result)
            result = np.reshape(result, (2, 1))
            training_data.append((data, result))

    test_data = []
    for filename in os.listdir(test_folder):
        img = cv2.imread(os.path.join(test_folder, filename), 0)
        if img is not None:
            data = np.array(preprocessor.prepare(img))
            data = np.reshape(data, (901, 1))
            result = 1 if "genuine" in filename else 0
            test_data.append((data, result))

    net = network.NeuralNetwork([901, 500, 500, 2])
    net.sgd(training_data, 10, 50, 0.01, test_data) 
开发者ID:gnbaron,项目名称:signature-recognition,代码行数:33,代码来源:sigrecog.py

示例12: main

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import __version__ [as 别名]
def main():
    print('OpenCV version {} '.format(cv2.__version__))

    current_dir = os.path.dirname(__file__)

    author = '021'
    training_folder = os.path.join(current_dir, 'data/training/', author)
    test_folder = os.path.join(current_dir, 'data/test/', author)

    training_data = []
    training_labels = []
    for filename in os.listdir(training_folder):
        img = cv2.imread(os.path.join(training_folder, filename), 0)
        if img is not None:
            data = preprocessor.prepare(img)
            training_data.append(data)
            training_labels.append([0, 1] if "genuine" in filename else [1, 0])

    test_data = []
    test_labels = []
    for filename in os.listdir(test_folder):
        img = cv2.imread(os.path.join(test_folder, filename), 0)
        if img is not None:
            data = preprocessor.prepare(img)
            test_data.append(data)
            test_labels.append([0, 1] if "genuine" in filename else [1, 0])

    sgd(training_data, training_labels, test_data, test_labels)


# Softmax Regression Model 
开发者ID:gnbaron,项目名称:signature-recognition,代码行数:33,代码来源:sigrecogtf.py

示例13: show_webcam_and_run

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import __version__ [as 别名]
def show_webcam_and_run(model, emoticons, window_size=None, window_name='webcam', update_time=10):
    """
    Shows webcam image, detects faces and its emotions in real time and draw emoticons over those faces.
    :param model: Learnt emotion detection model.
    :param emoticons: List of emotions images.
    :param window_size: Size of webcam image window.
    :param window_name: Name of webcam image window.
    :param update_time: Image update time interval.
    """
    cv2.namedWindow(window_name, WINDOW_NORMAL)
    if window_size:
        width, height = window_size
        cv2.resizeWindow(window_name, width, height)

    vc = cv2.VideoCapture(0)
    if vc.isOpened():
        read_value, webcam_image = vc.read()
    else:
        print("webcam not found")
        return

    while read_value:
        for normalized_face, (x, y, w, h) in find_faces(webcam_image):
            prediction = model.predict(normalized_face)  # do prediction
            if cv2.__version__ != '3.1.0':
                prediction = prediction[0]

            image_to_draw = emoticons[prediction]
            draw_with_alpha(webcam_image, image_to_draw, (x, y, w, h))

        cv2.imshow(window_name, webcam_image)
        read_value, webcam_image = vc.read()
        key = cv2.waitKey(update_time)

        if key == 27:  # exit on ESC
            break

    cv2.destroyWindow(window_name) 
开发者ID:PiotrDabrowskey,项目名称:facemoji,代码行数:40,代码来源:webcam.py

示例14: draw_result

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import __version__ [as 别名]
def draw_result(self, img, result):
        for i in range(len(result)):
            x = int(result[i][1])
            y = int(result[i][2])
            w = int(result[i][3] / 2)
            h = int(result[i][4] / 2)
            cv2.rectangle(img, (x - w, y - h), (x + w, y + h), (0, 255, 0), 2)
            cv2.rectangle(img, (x - w, y - h - 20),
                          (x + w, y - h), (125, 125, 125), -1)
            lineType = cv2.LINE_AA if cv2.__version__ > '3' else cv2.CV_AA
            cv2.putText(
                img, result[i][0] + ' : %.2f' % result[i][5],
                (x - w + 5, y - h - 7), cv2.FONT_HERSHEY_SIMPLEX, 0.5,
                (0, 0, 0), 1, lineType) 
开发者ID:hizhangp,项目名称:yolo_tensorflow,代码行数:16,代码来源:test.py

示例15: check_CV_version

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import __version__ [as 别名]
def check_CV_version():
    """
    ### check_CV_version

    Returns OpenCV binary in-use, version's first bit 
    """
    if parse_version(cv2.__version__) >= parse_version("4"):
        return 4
    else:
        return 3 
开发者ID:abhiTronix,项目名称:vidgear,代码行数:12,代码来源:helper.py


注:本文中的cv2.__version__方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。