Beispiel #1
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)
Beispiel #2
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 = []
Beispiel #3
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)
Beispiel #4
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)
Beispiel #5
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
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

# Create a raster object to slice the image
raster = Raster.Raster(cv_image, bed_size, line_width=1.0)
points = raster.raster()

Writer.points_to_gcode(filename, points, feedrate, z_hop=z_hop, z_tune=z_tune)