Esempio n. 1
0
def getNewProcessedImage(cv_image):
    gray_image = process_image.grayImage(cv_image)

    # If statements to process user filter options
    if blur_check is 1:
        # Blur the image

        if blur_type is not "Choose Filter":
            blur_image = process_image.blurImage(gray_image, blur_type)

    else:
        blur_image = gray_image

    if contour_check is 1:
        # Find contours of the image

        contour_image = process_image.contourImage(blur_image)

    else:

        contour_image = blur_image

    if threshold_check is 1:

        threshold_image = process_image.thresholdImage(blur_image, threshold_type)

    else:

        threshold_image = blur_image

    return threshold_image
Esempio n. 2
0
    def __init__(self, image, bed_size, line_width=1.0, lock_ratio=True):
        """
        Initialize the object
        :param image: [opencv image] The image to process and slice
        :param bed_size: [mm] [n x m] The size of the bed height (n) by width (m)
        :param line_width: [mm] The line width of the image (dots per mm)
        :param lock_ratio: [boolean] Crop the bed size to meet the image ratio
        """

        # The image to be processed
        self.original_image = image
        self.gray_image = process_image.grayImage(self.original_image, True)
        self.edge_image = process_image.edgeDetection(self.gray_image, True)
        self.inverted_image = process_image.invertImage(self.edge_image, True)

        cv.waitKey(0)

        # The resolution of the image
        self.line_width = line_width
        # Increasing the line width will result in a lower resolution
        # Decreasing the line width will result in a higher resolution
        # This might change depending on your marker size or XY accuracy

        # Bed specifications
        self.max_bed_height = bed_size[0]
        self.max_bed_width = bed_size[1]

        # Image specifications
        shape = image.shape
        self.image_height = shape[0]  # Vertical pixel number
        self.image_width = shape[1]  # Horizontal pixel number

        # If lock_ratio is on, the program will maintain the ratio of the image by reducing the bed-size
        # to maintain the height-width ratio of the image
        if lock_ratio:
            self.find_compression()

        self.width_number = math.floor(
            self.max_bed_width /
            self.line_width)  # Number of possible pixels in drawing width
        self.height_number = math.floor(
            self.max_bed_height /
            self.line_width)  # Number of possible pixels in drawing height

        self.white_pixels = []

        self.draw_arr = {
        }  # Create a dictionary for the image that needs to be drawn
        # Key: tuple: (y , x), where x is the pixel number width, and y is the pixel number height

        self.used = {
        }  # Store whether a particular pixel value has been used or not
        # Key: tuple: (y , x), where x is the pixel number width, and y is the pixel number height

        # Storage: Array: [pixelvalue, used]
        #       pixelvalue: The value of the pixel (typically 0 or 1)
        #       used: Boolean value representing whether it has been used or not

        print("This is the width and height of the resultant image: ",
              self.width_number, self.height_number)
Esempio n. 3
0
    def __init__(self, image, bed_size, line_width=1.0, lock_ratio=True):
        """
        Constructor, create a Slicer object to slice an image.
        :param image: [opencv image] The image to process and slice
        :param bed_size: [mm] [n x m] The size of the bed height (n) by width (m)
        :param line_width: [mm] The line width of the image (dots per mm)
        :param lock_ratio: [boolean] Crop the bed size to meet the image ratio
        """

        # The image to be processed
        self.original_image = image
        self.gray_image = process_image.grayImage(self.original_image, True)
        self.edge_image = process_image.edgeDetection(self.gray_image, True)
        self.inverted_image = process_image.invertImage(self.edge_image, True)

        cv.waitKey(0)
        cv.destroyAllWindows()

        # The resolution of the image
        self.line_width = line_width
        # Increasing the line width will result in a lower resolution
        # Decreasing the line width will result in a higher resolution
        # This might change depending on your marker size or XY accuracy

        # Bed specifications
        self.max_bed_height = bed_size[0]
        self.max_bed_width = bed_size[1]

        # Image specifications
        shape = image.shape
        self.image_height = shape[0]  # Vertical pixel number
        self.image_width = shape[1]  # Horizontal pixel number

        # If lock_ratio is on, the program will maintain the ratio of the image by reducing the bed-size
        # to maintain the height-width ratio of the image
        if lock_ratio:
            self.find_compression()

        self.width_number = math.floor(
            self.max_bed_width /
            self.line_width)  # Number of possible pixels in drawing width
        self.height_number = math.floor(
            self.max_bed_height /
            self.line_width)  # Number of possible pixels in drawing height

        self.white_pixels = []
Esempio n. 4
0
def calc_goals(cap, random_queue, inv_queue, board):
    while 1:
        small = getFrame(cap)
        gray = process.grayImage(small)
        #thresh = process.thresholdImage(gray, 1, 1)
        #eroded = process.morphTrans(thresh, 1, 2, 1)
        #contour = process.contourImage(gray)
        edge = process.edgeDetection(gray)
        inv_image = process.invertImage(edge)  # black is lines
        inv_queue.put(inv_image)
        random_goals = random_distr.createRandomDistribution(inv_image)

        #cv.imshow("Live", inv)

        random_queue.put(random_goals)

        board.chooseGoals(
            random_goals)  # Choose goals, using specific distribution

        #print("Added to queue")
        time.sleep(0.2)
Esempio n. 5
0
    def __init__(self, image, bed_size, line_width=1.0, lock_ratio=True):
        """
        Constructor, create a Raster object to slice an image. Raster uses
            individual points as opposed to lines
        :param image: [opencv image] The image to process and slice
        :param bed_size: [mm] [n x m] The size of the bed height (n) by width
                (m)
        :param line_width: [mm] The line width of the image (dots per mm)
        :param lock_ratio: [boolean] Crop the bed size to meet the image ratio
        """

        # The image to be processed
        self.original_image = image
        self.gray_image = process_image.grayImage(self.original_image, True)
        self.edge_image = process_image.edgeDetection(self.gray_image, True)
        self.inverted_image = process_image.invertImage(self.edge_image, True)

        # Show the images to the user
        cv.waitKey(0)
        cv.destroyAllWindows()

        # The resolution of the image
        self.line_width = line_width
        # Increasing the line width will result in a lower resolution
        # Decreasing the line width will result in a higher resolution
        # This might change depending on your marker size or XY accuracy

        # Bed specifications
        self.max_bed_height = bed_size[0]
        self.max_bed_width = bed_size[1]

        # Image specifications
        shape = image.shape
        print("Image size: ", shape)
        self.image_height = shape[0]  # Vertical pixel number
        self.image_width = shape[1]  # Horizontal pixel number

        # If lock_ratio is on, the program will maintain the ratio of the image
        # by reducing the bed-size to maintain the height-width ratio of the
        # image
        if lock_ratio:
            self = self.find_compression()

        self.width_number = math.floor(self.max_bed_width / self.line_width)

        self.height_number = math.floor(self.max_bed_height / self.line_width)

        print(self.width_number)
        print(self.height_number)

        self.white_pixels = cv.findNonZero(self.edge_image)

        blank_image = np.zeros((self.height_number, self.width_number),
                               np.uint8)

        for pixel in self.white_pixels:
            actual_pixel = pixel[0]

            width_pos = actual_pixel[0]
            height_pos = actual_pixel[1]

            cell_pixel_width = math.floor((width_pos / self.image_width) \
            * self.width_number)
            cell_pixel_height = math.floor((height_pos / self.image_height) \
            * self.height_number)

            # Toggle a specific square in the drawing array
            blank_image[cell_pixel_height - 1, cell_pixel_width - 1] = 255

        #img = process_image.morphTrans(blank_image, "erode", 2, 1)
        self.final_image = process_image.edgeDetection(blank_image)

        cv.imshow("eroded", blank_image)
        cv.imshow("final image", self.final_image)
        cv.waitKey(0)
        cv.destroyAllWindows()

        self.connected_image = self.create_grid()

        print("Created connected grid image")
        print("Size: w", self.width_number, ", h", self.height_number)
Esempio n. 6
0
import cv2 as cv
from ImageProcessing import process_image as process

cap = cv.VideoCapture(0)
while 1:

    ret, frame = cap.read()

    gray = process.grayImage(frame)
    thresh = process.thresholdImage(gray, 1, 1)
    eroded = process.morphTrans(thresh, 1, 2, 1)
    contour = process.contourImage(gray)
    edge = process.edgeDetection(gray)
    inv = process.invertImage(edge)

    #print(inv.shape)
    # resize = inv[250:350, 200:400]
    cv.imshow("Live", contour)
    if cv.waitKey(1) & 0xFF == ord('y'):
        print("Exiting")
        cv.destroyAllWindows()
        break
Esempio n. 7
0
bed_height = 280
bed_width = 220
bed_size = [bed_height, bed_width]  # The size of your printer bed
feedrate = 1000  # The feedrate of your x-y moves

z_hop = 3.0  # The total Z-hop between each dot (mm)
z_tune = 0.0  # Tune the Z-axis

# Take the picture
# takepicture.take_picture(filename) # Uncomment this if you want to take a picture

# open the image
cv_image = process_image.openImage(filename)

# Perform image processing
gray_image = process_image.grayImage(cv_image)
gray_edge_image = process_image.edgeDetection(gray_image)

# Show results of the cv functions
# Uncomment for debugging
resized = cv.resize(cv_image, (1320, 720))
cv.imshow('image', resized)
resized = cv.resize(gray_image, (1320, 720))
cv.imshow('gray_image', resized)
resized = cv.resize(process_image.invertImage(gray_edge_image), (1320, 720))
cv.imshow('gray_edge', resized)

# Wait for user to press key
cv.waitKey(0)
cv.destroyAllWindows()  # delete all windows
Esempio n. 8
0
    def raster(self):
        """
        Initiate the rastering of the loaded image
        :return: [[x1 y1] [x2 y2] ... [xn yn]] Array of points
        """

        # Cell density
        number_cells_width = math.floor(
            self.max_bed_width / self.line_width)  # Number of cells / side
        number_cells_height = math.floor(
            self.max_bed_height / self.line_width)  # Number of cells / side

        # Define a two dimensional array on where to draw, initialize to 0
        draw_arr = [[0 for x in range(number_cells_width)]
                    for y in range(number_cells_height)]

        # Image processing
        gray_image = process_image.grayImage(
            self.original_image)  # Convert image to gray
        gray_edge_image = process_image.edgeDetection(
            gray_image)  # Perform edge detection on gray image
        white_pixels = cv.findNonZero(
            gray_edge_image)  # Find all the pixels to draw

        # Change draw_arr depending on location of white_pixels
        for pixel2 in white_pixels:
            pixel = pixel2[0]

            # Transform from image space to draw_Arr space
            # findNonZero flips image X and Y
            pixel_width_pos = pixel[0]
            pixel_height_pos = pixel[1]

            cell_pixel_width = math.floor(
                (pixel_width_pos / self.image_width) * number_cells_width)
            cell_pixel_height = math.floor(
                (pixel_height_pos / self.image_height) * number_cells_height)

            # Change draw arr pixel
            draw_arr[cell_pixel_height - 1][cell_pixel_width - 1] += 1

        # Form array of lines to return
        points = []
        # Array of points [x, y]

        # Move from one point in draw_arr to the next
        for i in range(0, number_cells_width):

            for j in range(0, number_cells_height):

                # Determine whether to draw here, otherwise add point to lines after converting
                if draw_arr[j][i] > 0:

                    # Calculate the pixel coordinates to draw a point
                    pixel_width_pos = math.floor(
                        (i / number_cells_width) * self.max_bed_width)
                    pixel_height_pos = math.floor(
                        (j / number_cells_height) * self.max_bed_height)

                    # Now change to X-first, then Y [x, y]
                    points.append([pixel_width_pos, pixel_height_pos])

        return points