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


Python Preprocess.getImageToSendToContour方法代码示例

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


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

示例1: templateMatching

# 需要导入模块: import Preprocess [as 别名]
# 或者: from Preprocess import getImageToSendToContour [as 别名]
def templateMatching(im,elements, isPhoto):
    templates = ['images/templates/resistorT4.PNG', 'images/templates/resistorT2.PNG', 'images/templates/resistorT2_0degree.PNG', 'images/templates/resistorT2_45degree.PNG', 'images/templates/resistorT2_135degree.PNG','images/templates/resistorT4_0degree.PNG'];
    unmatched_resistors = [];
    for elem in elements:
        if elem[4] == 'o':
            unmatched_resistors += [elem];

    matched_resistors = {}
    matched_resistor_key = {}
    for threshold in [1, .9, .8, .7, .6, .5]:#, .5, .4, .3]:
        for restt in range(2, 15):
            for t in templates:
                templ = cv2.imread(t,cv2.CV_LOAD_IMAGE_COLOR);
                res = 20 - restt;
                template = cv2.resize(templ, dsize = (0,0), fx = res/10., fy = res/10., interpolation = cv2.INTER_CUBIC);
                [template, g]= Preprocess.getImageToSendToContour(template, False);
                w, h = template.shape[::-1]

                res = cv2.matchTemplate(im,template,cv2.TM_CCOEFF_NORMED)

                loc = np.where( res >= threshold)
                pts = []
                for pt in zip(*loc[::-1]):
                    pts += [[pt[0], pt[1], w, h, 'r']];
                indicesToRemove_ii = []
                indicesToRemove_i = []
                for i in range(0, len(unmatched_resistors)):
                    ii = -1;
                    minDistance = 1000000;
                    for ifindmin in range(0,len(pts)): 
                        dist = Postprocess.distance_resistor(unmatched_resistors[i][0:5], pts[ifindmin]);
                        if dist < minDistance and (ifindmin not in indicesToRemove_ii) and dist < 20 and dist < matched_resistor_key.get(i, 10000)*(threshold*1.1) and dist>7:
                            ii = ifindmin;
                            minDistance = dist;
                    if ii == -1:
                        continue;
                    matchresistor = unmatched_resistors[i][:];
                    matchresistor[0] = pts[ii][0]; #take on location of the element in the circuit
                    matchresistor[1] = pts[ii][1];
                    matchresistor[2] = pts[ii][2];
                    matchresistor[3] = pts[ii][3];
                    indicesToRemove_ii += [ii];
                    indicesToRemove_i  += [i];
                    matched_resistors[i] = matchresistor;
                    matched_resistor_key[i] = dist;
                #newunmatched = []
                #for i in range(0, len(unmatched_resistors)):
                #    if i not in indicesToRemove_i:
                #        newunmatched += [unmatched_resistors[i]]
                #unmatched_resistors = newunmatched;

 #   for r in matched_resistors:
 #       print r
    print matched_resistors
    print unmatched_resistors
    for i in matched_resistors.keys():
        pt = matched_resistors[i];
        cv2.rectangle(im, (pt[0], pt[1]), (pt[0] + pt[2], pt[1] + pt[3]), (0,0,0), 2)
        matchresistor = unmatched_resistors[i];
        matchresistor[0] = pt[0]; #take on location of the element in the circuit
        matchresistor[1] = pt[1];
        matchresistor[2] = pt[2];
        matchresistor[3] = pt[3];
    cv2.imshow('resistors', im);
 #   cv2.imshow('temp', template);

#    key = cv2.waitKey(0)
    return elements;
                    #cv2.rectangle(im, pt, (pt[0] + w, pt[1] + h), (0,0,255), 2)
开发者ID:nikhgarg,项目名称:CircuitSnap,代码行数:71,代码来源:Features.py

示例2: range

# 需要导入模块: import Preprocess [as 别名]
# 或者: from Preprocess import getImageToSendToContour [as 别名]
import cv2
import numpy as np
from matplotlib import pyplot as plt
import Preprocess;
#http://docs.opencv.org/trunk/doc/py_tutorials/py_imgproc/py_template_matching/py_template_matching.html#py-template-matching

#works, but only if the template size is same as size of object in the query image.
img_rgb = cv2.imread('images/photo3cropped.jpg',cv2.CV_LOAD_IMAGE_COLOR)
img_rgb = cv2.resize(img_rgb, dsize = (0,0), fx = .1, fy = .1, interpolation = cv2.INTER_CUBIC);

[img_gray, gray] = Preprocess.getImageToSendToContour(img_rgb, True);

#img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
templates = ['images/resistorT4.PNG', 'images/resistorT2.PNG', 'images/resistorT2_0degree.PNG', 'images/resistorT4_0degree.PNG'];
print img_gray;
for t in templates:
    templ = cv2.imread(t,cv2.CV_LOAD_IMAGE_COLOR);
    for res in range(6, 15):
        template = cv2.resize(templ, dsize = (0,0), fx = res/10., fy = res/10., interpolation = cv2.INTER_CUBIC);

        [template, g]= Preprocess.getImageToSendToContour(template, False);
        w, h = template.shape[::-1]

        res = cv2.matchTemplate(img_gray,template,cv2.TM_CCOEFF_NORMED)
        threshold = 0.4
        loc = np.where( res >= threshold)

        for pt in zip(*loc[::-1]):
            cv2.rectangle(img_gray, pt, (pt[0] + w, pt[1] + h), (0,0,255), 2)

cv2.imshow('template', template)
开发者ID:nikhgarg,项目名称:CircuitSnap,代码行数:33,代码来源:test_template_matching.py


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