Exemple #1
0
def main(argv):
    default_file = 'images/board.JPEG'
    filename = argv[0] if len(argv) > 0 else default_file
    # Loads an image
    src = cv.imread(cv.samples.findFile(filename), cv.IMREAD_GRAYSCALE)
    # Check if image is loaded fine
    if src is None:
        print('Error opening image!')
        print('Usage: hough_lines.py [image_name -- default ' + default_file +
              '] \n')
        return -1

    dst = cv.Canny(src, 50, 200, None, 3)

    # Copy edges to the images that will display the results in BGR
    cdst = cv.cvtColor(dst, cv.COLOR_GRAY2BGR)
    cdstP = np.copy(cdst)

    lines = cv.HoughLines(dst, 1, np.pi / 180, 150, None, 0, 0)

    if lines is not None:
        for i in range(0, len(lines)):
            rho = lines[i][0][0]
            theta = lines[i][0][1]
            a = math.cos(theta)
            b = math.sin(theta)
            x0 = a * rho
            y0 = b * rho
            pt1 = (int(x0 + 1000 * (-b)), int(y0 + 1000 * (a)))
            pt2 = (int(x0 - 1000 * (-b)), int(y0 - 1000 * (a)))
            cv.line(cdst, pt1, pt2, (0, 0, 255), 3, cv.LINE_AA)

    linesP = cv.HoughLinesP(dst, 1, np.pi / 180, 50, None, 50, 10)

    if linesP is not None:
        for i in range(0, len(linesP)):
            l = linesP[i][0]
            cv.line(cdstP, (l[0], l[1]), (l[2], l[3]), (0, 0, 255), 3,
                    cv.LINE_AA)

    y = int(round(1536 / 3))
    x = int(round(2048 / 3))
    src = cv.resize(cdst, (x, y))  # Resize image
    cdst = cv.resize(cdst, (x, y))  # Resize image
    cdstP = cv.resize(cdstP, (x, y))  # Resize image

    cv.imshow("Source", src)
    cv.imshow("Detected Lines (in red) - Standard Hough Line Transform", cdst)
    cv.imshow("Detected Lines (in red) - Probabilistic Line Transform", cdstP)

    cv.imwrite("./houghLines.png", cdstP)

    cv.waitKey()
    return 0
def upload_pic(path, layout):

    filet = path
    fl = path.split(".")[1]
    new_img = '/sdcard/' + fl + '_new.png'
    #pic=droid.cameraInteractiveCapturePicture(filet)
    res = urllib.urlopen(filet)
    image = np.asarray(bytearray(res.read()), dtype="uint8")
    image = cv2.imdecode(image, cv2.IMREAD_COLOR)
    # perform the actual resizing of the image according to scaling_factor
    height, width = image.shape[:2]
    resized = cv2.resize(image, (width / 3, height / 3),
                         interpolation=cv2.INTER_AREA)
    cv2.imwrite(new_img, resized)
    # Return gray sale image
    #gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

    print resized
    layout.views.result.text = "Processing ..."
    layout.views.preview.src = "file://" + new_img
    time.sleep(3)
    args = [
        'tesseract', '--tessdata-dir', '/data/data/com.termux/files/usr/share',
        new_img, 'stdout', '-l', 'eng', '--psm', '3', '--oem', '2'
    ]
    return run(args)
Exemple #3
0
    def callback(self, data):
        try:
            cv_image = self.bridge.imgmsg_to_cv(data, "bgr8")
        except CvBridgeError, e:
            rospy.logerr(e)

            bk_size = cv.Size(640, 480)
            cv.resize(cv_image, bk_image, bk_size)

            cv.ShowImage("Image window", cv_image)
            cv.WaitKey(3)

            try:
                self.image_pub.publish(self.bridge.cv_to_imgmsg(cv_image, "bgr8"))
            except CvVridgeError, e:
                rospy.logerr(e)
Exemple #4
0
def filtering(this_img, this_filter):
    img = np.zeros(this_img.shape)
    for i in range(this_img.shape[0]):
        img[i] = this_img[i].copy()

    # compute p and q
    height, width = img.shape
    new_height, new_width = height * 2, width * 2

    # create fp
    new_img = np.zeros((new_height, new_width))
    for i in range(height):
        for j in range(width):
            new_img[i][j] = img[i][j]

    img_fft = np.fft.fft2(new_img)
    # DFT and shift
    img_fft = np.fft.fftshift(img_fft)
    # multiply filter
    img_filtering = img_fft * cv.resize(np.abs(this_filter),
                                        (new_height, new_width))
    # shift
    img_filtering = np.fft.ifftshift(img_filtering)
    # IDFT and real
    img_ifft = np.real(np.fft.ifft2(img_filtering))
    # resize image
    final_img = np.zeros((height, width))
    for i in range(height):
        for j in range(width):
            final_img[i][j] = img_ifft[i][j]
    return final_img
def url_to_image():
	url = "http://192.168.43.1:8081/shot.jpg"
	# download the image, convert it to a NumPy array, and then read
	# it into OpenCV format
	res = urllib.urlopen(url)
	image = np.asarray(bytearray(res.read()), dtype="uint8")
	image = cv2.imdecode(image, cv2.IMREAD_COLOR)
	# perform the actual resizing of the image according to scaling_factor
	height, width = image.shape[:2]
	resized = cv2.resize(image, (width/scaling_factor, height/scaling_factor), interpolation = cv2.INTER_AREA)
	# Return gray sale image
	gray = cv2.cvtColor(resized, cv2.COLOR_BGR2GRAY)
	return gray
Exemple #6
0
def detect_face(path, layout):
    image = cv2.imread(path)
    height, width = image.shape[:2]
    resized = cv2.resize(image, (width / 5, height / 5))
    faces = faceCascade.detectMultiScale(resized,
                                         scaleFactor=1.2,
                                         minNeighbors=5,
                                         minSize=(5, 5),
                                         flags=cv2.cv.CV_HAAR_SCALE_IMAGE)
    (x, y, w, h) = faces[0]
    rect = faces[0]
    draw_rectangle(resized, rect)
    draw_text(resized, "Face", rect[0], rect[1] - 5)
    cv2.imwrite("/sdcard/face.jpg", resized)
    layout.views.preview.src = "file:///sdcard/face.jpg"
    return True
Exemple #7
0
import androidhelper
import cv
import socket
droid = androidhelper.Android()
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('enter your own same as in server', 5005))
while True:
    flag = s.recv(4096)
    if flag == 'ok':
        droid.cameraCapturePicture('/sdcard/caps/cap.jpg')
        img = cv.imread('/sdcard/caps/cap.jpg')
        img = cv.resize(img, (200, 200))
        img_str = cv.imencode('.jpg', img)[1].tostring()
        print len(img_str)
        s.send(img_str)
        flag2 = s.recv(4096)
s.close()
Exemple #8
0
def Unisize(CutImage):
    width=conf.getint('Unisize','width')
    hight=conf.getint('Unisize','hight')
    Inter_Method=conf.get('Unisize',Inter_Method)
    cv.resize(CutImage,(width,hight),Inter_Method)
    return image_Unisize
Exemple #9
0
# compute logarithm of filters
a_log = np.log(np.abs(a_shift) + 1)
b_log = np.log(np.abs(b_shift) + 1)
c_log = np.log(np.abs(c_shift) + 1)
a_separate_c_log = np.log(a_separate_c_shift + 1)
a_separate_r_log = np.log(a_separate_r_shift + 1)

# normalize filters
a_log_normalize = normalize(a_log)
b_log_normalize = normalize(b_log)
c_log_normalize = normalize(c_log)
a_separate_c_log_normalize = normalize(a_separate_c_log)
a_separate_r_log_normalize = normalize(a_separate_r_log)

# resize filters to show
a_separate_c_log_f = cv.resize(a_separate_c_log_normalize, (512, 512))
a_separate_r_log_f = cv.resize(a_separate_r_log_normalize, (512, 512))
a_log = cv.resize(a_log_normalize, (512, 512))
b_log = cv.resize(b_log_normalize, (512, 512))
c_log = cv.resize(c_log_normalize, (512, 512))

# write filters
cv.imwrite(out_path + 'a.jpg', a_log)
cv.imwrite(out_path + 'b.jpg', b_log)
cv.imwrite(out_path + 'c.jpg', c_log)
cv.imwrite(out_path + 'a_separate_c.jpg', a_separate_c_log_f)
cv.imwrite(out_path + 'a_separate_r.jpg', a_separate_r_log_f)
'''
# read filters
a_fft = cv.imread('a.jpg', 0)
b_fft = cv.imread('b.jpg', 0)