Example #1
0
def laplacian():
    cv.Smooth(src_image, dst_image, cv.CV_GAUSSIAN, 9, 9)
    dst_img = cv.CreateImage((dst_image.width, dst_image.height), 8, 1)
    cv.CvtColor(dst_image, dst_img, cv.CV_RGB2GRAY)
    cv.Laplace(dst_img, dst_img, 5)
    display(dst_img, "Laplacian")
    cv.WaitKey(0)
Example #2
0
    def applyEffect(self, image, width, height):
        ipl_img = cv2.cv.CreateImageHeader((image.shape[1], image.shape[0]),
                                           cv.IPL_DEPTH_8U, 3)
        cv2.cv.SetData(ipl_img, image.tostring(),
                       image.dtype.itemsize * 3 * image.shape[1])

        gray = cv.CreateImage((width, height), 8, 1)  #tuple as the first arg

        dst_img = cv.CreateImage(cv.GetSize(ipl_img), cv.IPL_DEPTH_8U,
                                 3)  #_16S  => cv2.cv.iplimage
        if self.effect == 'dilate':
            cv.Dilate(ipl_img, dst_img, None, 5)
        elif self.effect == 'laplace':
            cv.Laplace(ipl_img, dst_img, 3)
        elif self.effect == 'smooth':
            cv.Smooth(ipl_img, dst_img, cv.CV_GAUSSIAN)
        elif self.effect == 'erode':
            cv.Erode(ipl_img, dst_img, None, 1)

        cv.Convert(dst_img, ipl_img)
        return self.ipl2tk_image(dst_img)
Example #3
0
    elif len(sys.argv) == 2:
        capture = cv.CreateFileCapture(sys.argv[1])

    if not capture:
        print "Could not initialize capturing..."
        sys.exit(-1)

    cv.NamedWindow("Laplacian", 1)

    while True:
        frame = cv.QueryFrame(capture)
        if frame:
            if not laplace:
                planes = [cv.CreateImage((frame.width, frame.height), 8, 1) for i in range(3)]
                laplace = cv.CreateImage((frame.width, frame.height), cv.IPL_DEPTH_16S, 1)
                colorlaplace = cv.CreateImage((frame.width, frame.height), 8, 3)

            cv.Split(frame, planes[0], planes[1], planes[2], None)
            for plane in planes:
                cv.Laplace(plane, laplace, 3)
                cv.ConvertScaleAbs(laplace, plane, 1, 0)

            cv.Merge(planes[0], planes[1], planes[2], None, colorlaplace)

            cv.ShowImage("Laplacian", colorlaplace)

        if cv.WaitKey(10) != -1:
            break

    cv.DestroyWindow("Laplacian")
Example #4
0
            ds1 = ptdst(features[0], features[1])
            ds2 = ptdst(features[2], features[3])
            if max(ds1, ds2) / min(ds1, ds2) > 1.4: tracking = 0

            ds3 = ptdst(features[0], features[2])
            ds4 = ptdst(features[1], features[3])
            if max(ds3, ds4) / min(ds3, ds4) > 1.4: tracking = 0

            if ds1 < 10 or ds2 < 10 or ds3 < 10 or ds4 < 10: tracking = 0
            if tracking == 0: detected = 0

    #detection mode
    if tracking == 0:
        detected = 0
        cv.Smooth(grey, dst2, cv.CV_GAUSSIAN, 3)
        cv.Laplace(dst2, d)
        cv.CmpS(d, 8, d2, cv.CV_CMP_GT)

        if onlyBlackCubes:
            #can also detect on black lines for improved robustness
            cv.CmpS(grey, 100, b, cv.CV_CMP_LT)
            cv.And(b, d2, d2)

        #these weights should be adaptive. We should always detect 100 lines
        if lastdetected > dects: THR = THR + 1
        if lastdetected < dects: THR = max(2, THR - 1)
        li = cv.HoughLines2(d2, cv.CreateMemStorage(),
                            cv.CV_HOUGH_PROBABILISTIC, 1, 3.1415926 / 45, THR,
                            10, 5)

        #store angles for later
Example #5
0
import cv2.cv as cv
import cv2
import numpy as np

im = cv.LoadImage('WechatIMG92.jpeg', cv.CV_LOAD_IMAGE_COLOR)

# Laplace on a gray scale picture
gray = cv.CreateImage(cv.GetSize(im), 8, 1)
cv.CvtColor(im, gray, cv.CV_BGR2GRAY)

aperture = 3

dst = cv.CreateImage(cv.GetSize(gray), cv.IPL_DEPTH_32F, 1)
cv.Laplace(gray, dst, aperture)

cv.Convert(dst, gray)

thresholded = cv.CloneImage(im)
cv.Threshold(im, thresholded, 50, 255, cv.CV_THRESH_BINARY_INV)

cv.ShowImage('Laplaced grayscale', gray)
cv2.imwrite('~/Users/horace/Documents/TensorFlow/linedetection.jpg', gray)
cv.WaitKey(0)
#------------------------------------

# Laplace on color
planes = [cv.CreateImage(cv.GetSize(im), 8, 1) for i in range(3)]
laplace = cv.CreateImage(cv.GetSize(im), cv.IPL_DEPTH_16S, 1)
colorlaplace = cv.CreateImage(cv.GetSize(im), 8, 3)

cv.Split(im, planes[0], planes[1], planes[2],
GrayImg = cv.LoadImageM("cat.jpg", cv.CV_LOAD_IMAGE_GRAYSCALE)

SmoothGrayImg = cv.CreateMat(GrayImg.rows, GrayImg.cols, cv.CV_BLUR_NO_SCALE)
cv.Smooth(GrayImg,
          SmoothGrayImg,
          cv.CV_MEDIAN,
          param1=5,
          param2=0,
          param3=0,
          param4=0)
cv.SaveImage("Grey image.png", GrayImg)
cv.SaveImage("GraySmooth image.png", SmoothGrayImg)
#edge detection
EdgeDetection_Img = cv.CreateImage(cv.GetSize(SmoothGrayImg), cv.IPL_DEPTH_16S,
                                   cv.CV_BLUR_NO_SCALE)
cv.Laplace(SmoothGrayImg, EdgeDetection_Img)
cv.SaveImage(" EdgeDetection image.png", EdgeDetection_Img)
# set threshold
Thresholding = cv.CreateImage(cv.GetSize(EdgeDetection_Img), cv.IPL_DEPTH_16S,
                              cv.CV_BLUR_NO_SCALE)
cv.Threshold(EdgeDetection_Img, Thresholding, 20, 400, cv.CV_THRESH_BINARY_INV)
cv.SaveImage("Thresholding.png", Thresholding)

#Output from bilateral filter
im = cv.LoadImageM("cat.jpg")
BilateralImg = cv.CreateImage(cv.GetSize(im), cv.IPL_DEPTH_8U, 3)
cv.CvtColor(im, BilateralImg, cv.CV_RGB2Lab)

cv.Smooth(im, BilateralImg, cv.CV_BILATERAL, 100, 100, 100, 100)
cv.SaveImage("bilateral.png", BilateralImg)
finalImg = cv.CreateImage(cv.GetSize(GrayImg), cv.IPL_DEPTH_8U, 3)
Example #7
0
import matplotlib.pyplot as plt
import cv2
import numpy as np

import cv2.cv as cv

img = Image('/home/pi/Documents/Lab3/foto4.png')
(r, g, b) = img.splitChannels(False)

r.save('/home/pi/Documents/Lab3/red4.png')
g.save('/home/pi/Documents/Lab3/green4.png')
b.save('/home/pi/Documents/Lab3/blue4.png')

im = cv.LoadImage('/home/pi/Documents/Lab3/green4.png', cv.CV_LOAD_IMAGE_COLOR)

gray = cv.CreateImage(cv.GetSize(im), 8, 1)
cv.CvtColor(im, gray, cv.CV_BGR2GRAY)

aperture = 3

dst = cv.CreateImage(cv.GetSize(gray), cv.IPL_DEPTH_32F, 1)
cv.Laplace(gray, dst, aperture)

cv.Convert(dst, gray)

thresholded = cv.CloneImage(im)
cv.Threshold(im, thresholded, 100, 255, cv.CV_THRESH_BINARY_INV)

cv.ShowImage('Laplaced grayscale', gray)
cv.WaitKey(0)
Example #8
0
                cv.CV_MOP_GRADIENT)  # Apply a dilate - Erode

cv.Threshold(morphed, morphed, 30, 255, cv.CV_THRESH_BINARY_INV)
cv.ShowImage("Morphed green edge", morphed)
cv.SaveImage("green edge Morphed.png", dst)
cv.WaitKey(0)

enter = raw_input("Mostrar Laplace")

#laplace
#imagen en gris
gray = cv.CreateImage(cv.GetSize(im), 8, 1)
cv.CvtColor(im, gray, cv.CV_BGR2GRAY)
aperture = 3  #cambiar el aperture
dst = cv.CreateImage(cv.GetSize(gray), cv.IPL_DEPTH_32F, 1)
cv.Laplace(gray, dst, aperture)
cv.Convert(dst, gray)
thresholded = cv.CloneImage(im)
cv.Threshold(orig, thresholded, 100, 255, cv.CV_THRESH_BINARY_INV)

cv.ShowImage('Grayscale edge Laplace', gray)
cv.SaveImage("Grayscale edge Laplace.png", dst)
cv.WaitKey(0)
#azul
blue = cv.CreateImage(cv.GetSize(imblue), 8, 1)
cv.CvtColor(im, blue, cv.CV_BGR2GRAY)
aperture = 3  #cambiar el aperture
dst = cv.CreateImage(cv.GetSize(blue), cv.IPL_DEPTH_32F, 1)
cv.Laplace(blue, dst, aperture)
cv.Convert(dst, blue)
thresholded = cv.CloneImage(im)