python类Canny()的实例源码

tslsr.py 文件源码 项目:Speedy-TSLSR 作者: talhaHavadar 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def __bound_contours(roi):
    """
        returns modified roi(non-destructive) and rectangles that founded by the algorithm.
        @roi region of interest to find contours
        @return (roi, rects)
    """

    roi_copy = roi.copy()
    roi_hsv = cv2.cvtColor(roi, cv2.COLOR_RGB2HSV)
    # filter black color
    mask1 = cv2.inRange(roi_hsv, np.array([0, 0, 0]), np.array([180, 255, 125]))
    mask1 = cv2.morphologyEx(mask1, cv2.MORPH_CLOSE, cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3, 3)))
    mask1 = cv2.Canny(mask1, 100, 300)
    mask1 = cv2.GaussianBlur(mask1, (1, 1), 0)
    mask1 = cv2.Canny(mask1, 100, 300)

    # mask1 = cv2.morphologyEx(mask1, cv2.MORPH_CLOSE, cv2.getStructuringElement(cv2.MORPH_RECT, (3, 3)))

    # Find contours for detected portion of the image
    im2, cnts, hierarchy = cv2.findContours(mask1.copy(), cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
    cnts = sorted(cnts, key = cv2.contourArea, reverse = True)[:5] # get largest five contour area
    rects = []
    for c in cnts:
        peri = cv2.arcLength(c, True)
        approx = cv2.approxPolyDP(c, 0.02 * peri, True)
        x, y, w, h = cv2.boundingRect(approx)
        if h >= 15:
            # if height is enough
            # create rectangle for bounding
            rect = (x, y, w, h)
            rects.append(rect)
            cv2.rectangle(roi_copy, (x, y), (x+w, y+h), (0, 255, 0), 1);

    return (roi_copy, rects)
squares.py 文件源码 项目:PaperHelper 作者: EdgarNg1024 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def find_squares(img):
    img = cv2.GaussianBlur(img, (5, 5), 0)
    squares = []
    for gray in cv2.split(img):
        for thrs in xrange(0, 255, 26):
            if thrs == 0:
                bin = cv2.Canny(gray, 0, 50, apertureSize=5)
                bin = cv2.dilate(bin, None)
            else:
                retval, bin = cv2.threshold(gray, thrs, 255, cv2.THRESH_BINARY)
            bin, contours, hierarchy = cv2.findContours(bin, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
            for cnt in contours:
                cnt_len = cv2.arcLength(cnt, True)
                cnt = cv2.approxPolyDP(cnt, 0.02 * cnt_len, True)
                if len(cnt) == 4 and cv2.contourArea(cnt) > 1000 and cv2.isContourConvex(cnt):
                    cnt = cnt.reshape(-1, 2)
                    max_cos = np.max([angle_cos(cnt[i], cnt[(i + 1) % 4], cnt[(i + 2) % 4]) for i in xrange(4)])
                    if max_cos < 0.1:
                        squares.append(cnt)
    return squares
border_removal.py 文件源码 项目:idmatch 作者: maddevsio 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def remove_borders(image):
    ratio = image.shape[0] / 500.0
    orig = image.copy()
    image = resize(image, height=500)
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    gray = cv2.GaussianBlur(gray, (5, 5), 0)
    edged = cv2.Canny(gray, 75, 200)
    _, cnts, _ = cv2.findContours(edged.copy(), cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
    cv2.imshow('edged', edged)
    cnts = sorted(cnts, key=cv2.contourArea, reverse=True)
    screenCnt = None
    for c in cnts:
        peri = cv2.arcLength(c, True)
        approx = cv2.approxPolyDP(c, 0.02 * peri, True)
        print(len(approx) == 4)
        if len(approx) == 4:
            screenCnt = approx
            break
    cv2.drawContours(image, [screenCnt], -1, (0, 255, 0), 2)
    if screenCnt is not None and len(screenCnt) > 0:
        return four_point_transform(orig, screenCnt.reshape(4, 2) * ratio)
    return orig
find_bibs.py 文件源码 项目:bib-tagger 作者: KateRita 项目源码 文件源码 阅读 36 收藏 0 点赞 0 评论 0
def find_lines(img):
  edges = cv2.Canny(img,100,200)
  threshold = 60
  minLineLength = 10
  lines = cv2.HoughLinesP(edges, 1, np.pi/180, threshold, 0, minLineLength, 20);
  if (lines is None or len(lines) == 0):
      return

  #print lines
  for line in lines[0]:
    #print line
    cv2.line(img, (line[0],line[1]), (line[2],line[3]), (0,255,0), 2)
  cv2.imwrite("line_edges.jpg", edges)
  cv2.imwrite("lines.jpg", img)
__init__.py 文件源码 项目:beryl 作者: DanielJDufour 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def find_squares(img):
    img = cv2.GaussianBlur(img, (5, 5), 0)
    squares = []
    for gray in cv2.split(img):
        for thrs in xrange(0, 255, 26):
            if thrs == 0:
                bin = cv2.Canny(gray, 0, 50, apertureSize=5)
                bin = cv2.dilate(bin, None)
            else:
                _retval, bin = cv2.threshold(gray, thrs, 255, cv2.THRESH_BINARY)
            contours, _hierarchy = find_contours(bin, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
            for cnt in contours:
                x, y, w, h = cv2.boundingRect(cnt)
                cnt_len = cv2.arcLength(cnt, True)
                cnt = cv2.approxPolyDP(cnt, 0.02*cnt_len, True)
                area = cv2.contourArea(cnt)
                if len(cnt) == 4 and 20 < area < 1000 and cv2.isContourConvex(cnt):
                    cnt = cnt.reshape(-1, 2)
                    max_cos = np.max([angle_cos( cnt[i], cnt[(i+1) % 4], cnt[(i+2) % 4] ) for i in xrange(4)])
                    if max_cos < 0.1:
                        if (1 - (float(w) / float(h)) <= 0.07 and 1 - (float(h) / float(w)) <= 0.07):
                            squares.append(cnt)
    return squares
chess_detection.py 文件源码 项目:WeiQiRecognition 作者: JDython 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def get_chessboard_lines(binary_img):
    edges = cv2.Canny(binary_img,50,120)
    cv2.imshow('image',edges)
    k = cv2.waitKey(0) & 0xFF
    if k == 27:
        cv2.destroyAllWindows()
    lines_data = cv2.HoughLines(edges,1,np.pi/180,110)

    parallel_lines = []
    vertical_lines = []
    for rho,theta in lines_data[0]:
        #print 'rho:  '+str(rho)+'theta:  '+str(theta)
        if 2>theta > 1:
            vertical_lines.append([theta,rho])
        elif theta < 1 :
            parallel_lines.append([theta,rho])
        elif theta>3:
            parallel_lines.append([theta,rho])

        a = np.cos(theta)
        b = np.sin(theta)
        x0 = a*rho
        y0 = b*rho
        x1 = int(x0 + 1000*(-b))
        y1 = int(y0 + 1000*(a))
        x2 = int(x0 - 1000*(-b))
        y2 = int(y0 - 1000*(a))
        cv2.line(edges,(x1,y1),(x2,y2),(255,0,0),2)
    cv2.imshow('image',edges)
    k = cv2.waitKey(0) & 0xFF
    if k == 27:
        cv2.destroyAllWindows()

    vertical_lines=sorted(vertical_lines,key=lambda x: abs(x[1]))
    parallel_lines=sorted(parallel_lines,key=lambda x: abs(x[1]))
    return vertical_lines,parallel_lines
cut.py 文件源码 项目:yonkoma2data 作者: esuji5 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def homography(self, img, outdir_name=''):
        orig = img
        # 2??????
        gray = cv2.cvtColor(orig, cv2.COLOR_BGR2GRAY)
        gauss = cv2.GaussianBlur(gray, (5, 5), 0)
        canny = cv2.Canny(gauss, 50, 150)

        # 2??????????
        contours = cv2.findContours(canny, cv2.RETR_LIST, cv2.CHAIN_APPROX_NONE)[1]
        # ???????????
        contours.sort(key=cv2.contourArea, reverse=True)

        if len(contours) > 0:
            arclen = cv2.arcLength(contours[0], True)
            # ???????????
            approx = cv2.approxPolyDP(contours[0], 0.01 * arclen, True)
            # warp = approx.copy()
            if len(approx) >= 4:
                self.last_approx = approx.copy()
            elif self.last_approx is not None:
                approx = self.last_approx
        else:
            approx = self.last_approx
        rect = self.get_rect_by_points(approx)
        # warped = self.transform_by4(orig, warp[:, 0, :])
        return orig[rect[0]:rect[1], rect[2]:rect[3]]
piwall.py 文件源码 项目:piwall-cvtools 作者: infinnovation 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def find_squares(img, cos_limit = 0.1):
    print('search for squares with threshold %f' % cos_limit)
    img = cv2.GaussianBlur(img, (5, 5), 0)
    squares = []
    for gray in cv2.split(img):
        for thrs in xrange(0, 255, 26):
            if thrs == 0:
                bin = cv2.Canny(gray, 0, 50, apertureSize=5)
                bin = cv2.dilate(bin, None)
            else:
                retval, bin = cv2.threshold(gray, thrs, 255, cv2.THRESH_BINARY)
            bin, contours, hierarchy = cv2.findContours(bin, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
            for cnt in contours:
                cnt_len = cv2.arcLength(cnt, True)
                cnt = cv2.approxPolyDP(cnt, 0.02*cnt_len, True)
                if len(cnt) == 4 and cv2.contourArea(cnt) > 1000 and cv2.isContourConvex(cnt):
                    cnt = cnt.reshape(-1, 2)
                    max_cos = np.max([angle_cos( cnt[i], cnt[(i+1) % 4], cnt[(i+2) % 4] ) for i in xrange(4)])
                    if max_cos < cos_limit :
                        squares.append(cnt)
                    else:
                        #print('dropped a square with max_cos %f' % max_cos)
                        pass
    return squares

###
### Version V2.  Collect meta-data along the way,  with commentary added.
###
find_bibs.py 文件源码 项目:bib-tagger 作者: KateRita 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def find_bibs(image):
  gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY);
  binary = cv2.GaussianBlur(gray,(5,5),0)
  ret,binary = cv2.threshold(binary, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU);
  #binary = cv2.adaptiveThreshold(binary, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 11, 2)
  #ret,binary = cv2.threshold(binary, 190, 255, cv2.THRESH_BINARY);

  #lapl = cv2.Laplacian(image,cv2.CV_64F)
  #gray = cv2.cvtColor(lapl, cv2.COLOR_BGR2GRAY);
  #blurred = cv2.GaussianBlur(lapl,(5,5),0)
  #ret,binary = cv2.threshold(blurred, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU);
  #cv2.imwrite("lapl.jpg", lapl)

  edges = cv2.Canny(image,175,200)
  cv2.imwrite("edges.jpg", edges)
  binary = edges

  cv2.imwrite("binary.jpg", binary)
  contours,hierarchy = find_contours(binary)

  return get_rectangles(contours)
imutils.py 文件源码 项目:AutomatorX 作者: xiaoyaojjian 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def diff_rect(img1, img2, pos=None):
    """find counters include pos in differences between img1 & img2 (cv2 images)"""
    diff = cv2.absdiff(img1, img2)
    diff = cv2.GaussianBlur(diff, (3, 3), 0)
    edges = cv2.Canny(diff, 100, 200)
    _, thresh = cv2.threshold(edges, 0, 255, cv2.THRESH_BINARY)
    contours, _ = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)
    if not contours:
        return None
    contours.sort(key=lambda c: len(c))
    # no pos provide, just return the largest different area rect
    if pos is None:
        cnt = contours[-1]
        x0, y0, w, h = cv2.boundingRect(cnt)
        x1, y1 = x0+w, y0+h
        return (x0, y0, x1, y1)
    # else the rect should contain the pos
    x, y = pos
    for i in range(len(contours)):
        cnt = contours[-1-i]
        x0, y0, w, h = cv2.boundingRect(cnt)
        x1, y1 = x0+w, y0+h
        if x0 <= x <= x1 and y0 <= y <= y1:
            return (x0, y0, x1, y1)
StreamParser.py 文件源码 项目:meleedb-segment 作者: sashahashi 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def multiple_template_match(self, feature, scene, roi=None, scale=None, min_scale=0.5, max_scale=1.0, max_distance=14, min_corr=0.8, debug=False, threshold_min=50, threshold_max=200):
        if roi is not None:
            scene = scene[roi.top:(roi.top + roi.height), roi.left:(roi.left + roi.width)]

        if not scale:
            scale = self.find_best_scale(feature, scene, min_scale=min_scale, max_scale=max_scale, min_corr=min_corr)
        peaks = []

        if scale:
            scaled_feature = cv2.resize(feature, (0, 0), fx=scale, fy=scale)

            canny_scene = cv2.Canny(scene, threshold_min, threshold_max)
            canny_feature = cv2.Canny(scaled_feature, threshold_min, threshold_max)

            # Threshold for peaks.
            corr_map = cv2.matchTemplate(canny_scene, canny_feature, cv2.TM_CCOEFF_NORMED)
            _, max_corr, _, max_loc = cv2.minMaxLoc(corr_map)

            good_points = list(zip(*np.where(corr_map >= max_corr - self.tolerance)))
            if debug:
                print(max_corr, good_points)
            clusters = self.get_clusters(good_points, max_distance=max_distance)
            peaks = [max([(pt, corr_map[pt]) for pt in cluster], key=lambda pt: pt[1]) for cluster in clusters]

        return (scale, peaks)
videoTransforms.py 文件源码 项目:Computer-Vision 作者: PratikRamdasi 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def applyTransform(self):
        self.framing(self.path)
        self.height,self.width=cv2.imread("Frames/1.jpg").shape[:2]

        # write transformed video

        out = cv2.VideoWriter("changedOutput.mp4",cv.CV_FOURCC('a','v','c','1'), 30.0, (self.width, self.height))
        folder=self.sort_files()

        # write Transformed video frames

        for i in folder:
            pic="Frames/"+str(i)+".jpg"
            Newpic=cv2.imread(pic,0)
            frame=cv2.Canny(Newpic,100,200)
            cv2.imwrite(pic,frame)
            Newpic=cv2.imread(pic)
            img=cv2.flip(Newpic,0)
            out.write(img)
        out.release()

    # Writing output video file
recognize_line.py 文件源码 项目:WeiQiRecognition 作者: JDython 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def lineRecognizer(path):
    '''
    :param path ????????
    :returns lines_data ?????????resize_pic ??????
    '''
    img = cv2.imread(path,cv2.IMREAD_GRAYSCALE)
    resize_pic=img
    #resize_pic=cv2.resize(img,(640,480),interpolation=cv2.INTER_CUBIC)
    edges = cv2.Canny(resize_pic,50,150)
    lines_data = cv2.HoughLines(edges,1,np.pi/180,150)
    return lines_data,resize_pic
ChessBoard.py 文件源码 项目:ChessBot 作者: pakhandi 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def __init__(self, blankBoard, fullBoard, InitialVerticesCount, blackThreshold, FinalVerticesCount=150, Offset=15):

        self.INITIAL_VERTICES_COUNT = InitialVerticesCount
        self.FINAL_VERTICES_COUNT = FinalVerticesCount
        self.OFFSET = Offset
        self.blackThreshold = blackThreshold

        self.blankBoard = cv2.imread(blankBoard)
        self.fullBoard = cv2.imread(fullBoard)

        # get the edges from the images
        self.blankBoardEdges = cv2.Canny(self.blankBoard, 0, 100)
        self.fullBoardEdges = cv2.Canny(self.fullBoard, 0, 100)

        # try to identify the four corners in the blankBoard
        self.detectFourCorners(self.blankBoardEdges)

        # process both the images
        self.blankBoardMatrix = self.process(self.blankBoard, self.blankBoardEdges, self.blankName)
        self.fullBoardMatrix = self.process(self.fullBoard, self.fullBoardEdges, self.fullName)

    # fucntion to sharpen the image
videotopictures.py 文件源码 项目:SBB4-damage-tracker 作者: whorn 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def createTrainingData(filename,time_start,time_stop):
    vidcap = cv2.VideoCapture(filename)
    try:
        os.makedirs("trainingdata_"+filename)
    except OSError:
        pass
    os.chdir("trainingdata_"+filename)
    length = int(vidcap.get(cv2.CAP_PROP_FRAME_COUNT))
    fps = int(vidcap.get(cv2.CAP_PROP_FPS))
    for time in range(time_start,time_stop):
        vidcap.set(cv2.CAP_PROP_POS_MSEC,time*1000)
        success,image = vidcap.read()
        image = cv2.medianBlur(image,7)
        resized = imutils.resize(image, width=800)
        p1 = resized[370:430,220:300]
        p2 = resized[370:430,520:600]
        p1 = cv2.Canny(p1, 400, 100, 255)
        p2 = cv2.Canny(p2, 400, 100, 255)
        cv2.imwrite('p1_'+str(time)+".png",p1)
        cv2.imwrite('p2_'+str(time)+".png",p2)
    os.chdir("..")
scan2.py 文件源码 项目:card-scanner 作者: RFVenter 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def filter_image(image, canny1=10, canny2=10, show=False):
    # compute the ratio of the old height to the new height, and resize it
    image = imutils.resize(image, height=scale_factor, interpolation=cv2.INTER_CUBIC)

    # convert the image to grayscale, blur it, and find edges in the image
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    gray = cv2.GaussianBlur(gray, (5, 5), 0)
    edged = cv2.Canny(gray, canny1, canny2)

    # show the image(s)
    if show:
        cv2.imshow("Edged", edged)
        cv2.waitKey(0)
        cv2.destroyAllWindows()

    return edged
scan.py 文件源码 项目:card-scanner 作者: RFVenter 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def filter_image(image, canny1=10, canny2=10, show=False):
    # compute the ratio of the old height to the new height, and resize it
    image = imutils.resize(image, height=scale_factor, interpolation=cv2.INTER_CUBIC)

    # convert the image to grayscale, blur it, and find edges in the image
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    gray = cv2.GaussianBlur(gray, (5, 5), 0)
    edged = cv2.Canny(gray, canny1, canny2)

    # show the image(s)
    if show:
        cv2.imshow("Edged", edged)
        cv2.waitKey(0)
        cv2.destroyAllWindows()

    return edged
scan - 0160708.py 文件源码 项目:card-scanner 作者: RFVenter 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def filter_image(image, canny1=5, canny2=5, show=False):
    # compute the ratio of the old height to the new height, and resize it
    image = imutils.resize(image, height=scale_factor, interpolation=cv2.INTER_NEAREST)

    # convert the image to grayscale, blur it, and find edges in the image
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    blurred = cv2.GaussianBlur(gray, (5, 5), 0)
    edged = cv2.Canny(blurred, canny1, canny2)

    # show the image(s)
    if show:
        cv2.imshow("Edged", edged)
        cv2.waitKey(0)
        cv2.destroyAllWindows()

    return edged
scan.py 文件源码 项目:card-scanner 作者: RFVenter 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def filter_image(image, canny1=10, canny2=10, show=False):
    # compute the ratio of the old height to the new height, and resize it
    image = imutils.resize(image, height=scale_factor, interpolation=cv2.INTER_NEAREST)

    # convert the image to grayscale, blur it, and find edges in the image
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    gray = cv2.GaussianBlur(gray, (5, 5), 0)
    edged = cv2.Canny(gray, canny1, canny2)

    # show the image(s)
    if show:
        cv2.imshow("Edged", edged)
        cv2.waitKey(0)
        cv2.destroyAllWindows()

    return edged
Imagehandler.py 文件源码 项目:QRCodeReader 作者: Griffintaur 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def GetImageContour(self):
        thresholdImage = self.__convertImagetoBlackWhite()  #B & W with adaptive threshold
        thresholdImage = cv.Canny(thresholdImage, 100, 200) #Edges by canny edge detection
        thresholdImage, contours, hierarchy = cv.findContours(
            thresholdImage, cv.RETR_TREE, cv.CHAIN_APPROX_SIMPLE)
        self.Contours = contours
        # uncomment this to see the contours on the image
        # cv2.drawContours(thresholdImage, contours, -1, (0,255,0), 3)
        # patternFindingObj=PatternFinding()
        # areas= [cv.contourArea(contour) for contour in contours]
        # for index in xrange(len(contours)):
        #     IsPattern=self.IsPossibleQRContour(index)
        #     if IsPattern is True:
        #         x,y,w,h=cv.boundingRect(contours[index])
        #         cv.rectangle(self.imageOriginal,(x,y),(x+w,y+h),(0,0,255),2)
        #         cv.imshow("hello",self.imageOriginal)
        # maxAreaIndex=np.argmax(areas)
        # x,y,w,h=cv.boundingRect(contours[maxAreaIndex])
        # cv.rectangle(self.image2,(x,y),(x+w,y+h),(0,255,0),2)
        # cv.imshow("hello",self.imageOriginal)
        # cv.waitKey(0)
        #cv.destroyAllWindows()
        contour_group = (thresholdImage, contours, hierarchy)
        return contour_group
lane_detect.py 文件源码 项目:hazcam 作者: alex-sherman 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def run_step(self, img, thrs1, thrs2, debug):
        self.lines = []
        self.lines2 = []
        height, width, c = img.shape
        gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

        if(self.previous_mask_left == None):
            self.previous_mask_left = np.zeros((height, width, 1), np.uint8)
        if(self.previous_mask_right == None):
            self.previous_mask_right = np.zeros((height, width, 1), np.uint8)
        self.edge = cv2.Canny(gray, thrs1, thrs2, apertureSize=5)
        self.masked_edges_left, self.current_mask_left, self.previous_mask_left, self.left_line \
            = self.update_edge_mask(self.previous_mask_left, self.left_line, -1, thrs1, thrs2, debug)
        self.masked_edges_right, self.current_mask_right, self.previous_mask_right, self.right_line \
            = self.update_edge_mask(self.previous_mask_right, self.right_line, 1, thrs1, thrs2, debug)

        self.segment_history = self.boxes
        self.boxes = [find_lane_markers(self.masked_edges_left), find_lane_markers(self.masked_edges_right)]
        self.eps = [ep[-2:] + combine_eps(cur, past)[:2] for cur, past, ep in zip(self.boxes, self.segment_history, self.eps)]
        self.depth_pairs = [(a, b) for eps in self.eps for ep in eps if len(ep) > 0 for a, b in zip(ep[0], ep[1])[:2]]
10-PiStorms_icontracker.py 文件源码 项目:PiStorms 作者: mindsensors 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def findSquare( self,frame ):
        gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
        blurred = cv2.GaussianBlur(gray, (7, 7), 0)
        edged = cv2.Canny(blurred, 60, 60)
        # find contours in the edge map
        (cnts, _) = cv2.findContours(edged.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
        # loop over our contours to find hexagon
        cnts = sorted(cnts, key = cv2.contourArea, reverse = True)[:50]
        screenCnt = None
        for c in cnts:
            # approximate the contour
            peri = cv2.arcLength(c, True)
            approx = cv2.approxPolyDP(c, 0.004 * peri, True)
            # if our approximated contour has four points, then
            # we can assume that we have found our squeare

            if len(approx) >= 4:
                screenCnt = approx
                x,y,w,h = cv2.boundingRect(c)
                cv2.drawContours(image, [approx], -1, (0, 0, 255), 1)
                #cv2.imshow("Screen", image)
                #create the mask and remove rest of the background
                mask = np.zeros(image.shape[:2], dtype = "uint8")
                cv2.drawContours(mask, [screenCnt], -1, 255, -1)
                masked = cv2.bitwise_and(image, image, mask = mask)
                #cv2.imshow("Masked",masked  )
                #crop the masked image to to be compared to referance image
                cropped = masked[y:y+h,x:x+w]
                #scale the image so it is fixed size as referance image
                cropped = cv2.resize(cropped, (200,200), interpolation =cv2.INTER_AREA)

                return cropped
image_preparator.py 文件源码 项目:autonomous_driving 作者: StatueFungus 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def edge_detection(self, image, threshold1, threshold2, aperture):
        '''
            Methode erkennt Kanten auf einem Bild basierend auf dem Canny-Algorithmus.

            Parameter
            ---------
            image : Bild
            threshold1 : Integer
            threshold2 : Integer
            aperture : Integer

            Rückgabe
            ---------
            image : Bild

        '''
        return cv2.Canny(image, threshold1, threshold2, aperture)
edge_utils.py 文件源码 项目:pybot 作者: spillai 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def canny(im, blur=3): 
    im_blur = cv2.blur(im, (blur,blur))
    return cv2.Canny(im_blur, 50, 150, blur)
guiutils.py 文件源码 项目:opencv-gui-helper-tool 作者: maunesh 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def _render(self):
        self._smoothed_img = cv2.GaussianBlur(self.image, (self._filter_size, self._filter_size), sigmaX=0, sigmaY=0)
        self._edge_img = cv2.Canny(self._smoothed_img, self._threshold1, self._threshold2)
        cv2.imshow('smoothed', self._smoothed_img)
        cv2.imshow('edges', self._edge_img)
vision_util.py 文件源码 项目:Vision2016 作者: Team3309 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def canny(img, lowThreshold):
    """
    Performs canny edge detection on the provided grayscale image.
    :param img: a grayscale image
    :param lowThreshold: threshold for the canny operation
    :return: binary image containing the edges found by canny
    """

    dst = np.zeros(img.shape, dtype=img.dtype)
    cv2.blur(img, (3, 3), dst)

    # canny recommends that the high threshold be 3 times the low threshold
    # the kernel size is 3 as defined above
    return cv2.Canny(dst, lowThreshold, lowThreshold * 3, dst, 3)
robot.py 文件源码 项目:ab2016-ros-gazebo 作者: akademikbilisim 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def camera_callback(self, msg):
        try:
            self.camera_data = self.cv_bridge.imgmsg_to_cv2(msg, "bgr8")
        except cv_bridge.CvBridgeError:
            return

        gray = cv2.cvtColor(self.camera_data, cv2.COLOR_BGR2GRAY)
        blur = cv2.GaussianBlur(gray, (5, 5), 0)
        canny = cv2.Canny(blur, 30, 150)

        cv2.imshow("Robot Camera", canny)
        cv2.waitKey(1)
BoundaryExtraction.py 文件源码 项目:SummerProject_MacularDegenerationDetection 作者: WDongYuan 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def EdgeDetection(img):
    img = cv2.fastNlMeansDenoising(img,None,3,7,21)
    _,img = cv2.threshold(img,30,255,cv2.THRESH_TOZERO)
    denoise_img = img
    laplacian = cv2.Laplacian(img,cv2.CV_64F)
    sobelx = cv2.Sobel(img,cv2.CV_64F,1,0,ksize=5)  # x
    sobely = cv2.Sobel(img,cv2.CV_64F,0,1,ksize=3)  # y
    canny = cv2.Canny(img,100,200)
    contour_image, contours, hierarchy = cv2.findContours(img, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)

    return {"denoise":denoise_img,"laplacian":laplacian,"canny":canny,"sobely":sobely,"sobelx":sobelx,"contour":contour_image}

# GrayScale Image Convertor
# https://extr3metech.wordpress.com
BoundaryExtraction.py 文件源码 项目:SummerProject_MacularDegenerationDetection 作者: WDongYuan 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def EdgeDetection(img):
    img = cv2.fastNlMeansDenoising(img,None,3,7,21)
    _,img = cv2.threshold(img,30,255,cv2.THRESH_TOZERO)
    denoise_img = img
    laplacian = cv2.Laplacian(img,cv2.CV_64F)
    sobelx = cv2.Sobel(img,cv2.CV_64F,1,0,ksize=5)  # x
    sobely = cv2.Sobel(img,cv2.CV_64F,0,1,ksize=3)  # y
    canny = cv2.Canny(img,100,200)
    contour_image, contours, hierarchy = cv2.findContours(img, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)

    return {"denoise":denoise_img,"laplacian":laplacian,"canny":canny,"sobely":sobely,"sobelx":sobelx,"contour":contour_image}

# GrayScale Image Convertor
# https://extr3metech.wordpress.com
tslsr.py 文件源码 项目:Speedy-TSLSR 作者: talhaHavadar 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def __filterRedColor(image_hsv):
    """
        Filters the red color from image_hsv and returns mask.
    """
    mask1 = cv2.inRange(image_hsv, np.array([0, 100, 65]), np.array([10, 255, 255]))
    mask2 = cv2.inRange(image_hsv, np.array([155, 100, 70]), np.array([179, 255, 255]))
    mask = mask1 + mask2
    mask = cv2.morphologyEx(mask, cv2.MORPH_OPEN, cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(2,2)))
    mask = cv2.Canny(mask, 50, 100)
    mask = cv2.GaussianBlur(mask, (13, 13), 0)
    mask = cv2.morphologyEx(mask, cv2.MORPH_OPEN, cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(2,2)))
    return mask


问题


面经


文章

微信
公众号

扫码关注公众号