예제 #1
0
def doneImages():
    meta_json = os.path.join("stacked", "test_data.json")
    with open(meta_json) as json_file:
        data = json.load(json_file)
        images = data["images"]
        image_names = []
        for image in images:
            name = image["image_name"].split(".")[0]
            image_names.append(name[:-7])
    return image_names
    #if __name__ == '__main__':
    bombsCoor = [(39.0338362, -104.8850707), (39.0337238, -104.8842394)]

    index = 0
    imagePath = os.path.join('..', 'test_data')
    for file in os.listdir(imagePath):
        stripped_file = file.split(".")[0]
        FILE = stripped_file[:-1]
        if FILE not in doneImages():
            print("stacking: " + FILE)
            image_wild = FILE + '*.tif'
            imageNames = glob.glob(os.path.join(imagePath, image_wild))
            #panelNames = glob.glob(os.path.join(imagePath,'IMG_0111_*.tif'))

            stack.stackImages(FILE, imageNames)

            file = FILE + '3.tif'
            data.createJson(file, bombsCoor)
            index += 1
    print(str(index) + " images stacked")
예제 #2
0
def driver():
    '''
    main driver code for the pulling 6 bands of an image, then stacking them, updating the metajson data
    then push the stacked image and metadata back to the server
    '''
    #opening directpry json
    filename = 'directory.json'
    with open(filename) as json_file:
        dir_json = json.load(json_file)

    #getting down to each file on the server
    sets = dir_json["files"]
    for set in sets:
        batches = dir_json["files"][set]
        for batch in batches:
            files = dir_json["files"][set][batch]
            for file in files:
                #baseName is the file name without its band number
                baseName = file.split('_')[0] + '_' + file.split('_')[1] + '_'

                # checking if the file has already been stacked
                if check_uploads(baseName):

                    #post current working file
                    post_current_file(baseName)
                    #getting each band for the image
                    for band in range(1, 7):
                        image = baseName + str(band) + '.tif'
                        url = baseURL + '/' + "files" + '/' + set + '/' + batch + '/' + image
                        print(url)
                        #pullling the image band
                        pull_image(url)

                    #giving the images to stack function
                    image_wild = baseName + '*.tif'
                    imagePath = os.path.join('..', 'data')
                    imageNames = glob.glob(os.path.join(imagePath, image_wild))
                    successCode = stack.stackImages(baseName, imageNames)
                    if successCode != -1:
                        file = baseName + '3.tif'
                        data.updateDatabase(file, bombsCoor)
                        stacked = '../processing/stacked/' + baseName + 'stacked.tiff'
                        os.remove(stacked)
                    else:
                        #error handling
                        print(baseName + ' skipped due to stacking errors')
                        #adding file to errorFile.txt
                        update_errorFiles(baseName)
                    #deleting the bands
                    delete_images(image_wild)
예제 #3
0
##takes a really long time to run

sr = dnn_superres.DnnSuperResImpl_create()

image = cv2.imread('Ressources/picture_png_1.PNG')
image2 = cv2.imread('Ressources/picture_png_2.PNG')
image3 = cv2.imread('Ressources/picture_png_3.PNG')
image5 = cv2.imread('Ressources/picture_png_5.PNG')

path = "Ressources/EDSR_x4_best_performing.pb"
sr.readModel(path)

sr.setModel("edsr", 4)

result = sr.upsample(image)
result2 = sr.upsample(image2)
result3 = sr.upsample(image3)
result5 = sr.upsample(image5)

cv2.imwrite("./upscaled1.png", result)
cv2.imwrite("./upscaled2.png", result2)
cv2.imwrite("./upscaled3.png", result3)
cv2.imwrite("./upscaled5.png", result5)

imgStack = stackImages(
    0.5,
    ([image, result], [image2, result2], [image3, result3], [image5, result5]))
cv2.imshow("stacked", imgStack)

cv2.waitKey(0)
예제 #4
0
cv.resizeWindow("TrackBars", width, height)
cv.createTrackbar("Hue Min", "TrackBars", 29, 179, empty)
cv.createTrackbar("Hue Max", "TrackBars", 179, 179, empty)

cv.createTrackbar("Sat Min", "TrackBars", 39, 255, empty)
cv.createTrackbar("Sat Max", "TrackBars", 255, 255, empty)

cv.createTrackbar("Val Min", "TrackBars", 43, 255, empty)
cv.createTrackbar("Val Max", "TrackBars", 255, 255, empty)

while (cv.waitKey(1) != ord('q')):
    success, img = cam.read()
    imgHSV = cv.cvtColor(img, cv.COLOR_BGR2HSV)

    h_min = cv.getTrackbarPos("Hue Min", "TrackBars")
    h_max = cv.getTrackbarPos("Hue Max", "TrackBars")

    s_min = cv.getTrackbarPos("Sat Min", "TrackBars")
    s_max = cv.getTrackbarPos("Sat Max", "TrackBars")

    v_min = cv.getTrackbarPos("Val Min", "TrackBars")
    v_max = cv.getTrackbarPos("Val Max", "TrackBars")

    lower = np.array([h_min, s_min, v_min])
    upper = np.array([h_max, s_max, v_max])
    mask = cv.inRange(imgHSV, lower, upper)

    imgRes = cv.bitwise_and(img, img, mask=mask)
    imgStack = stackImages(1, ([img, imgHSV, imgRes]))
    cv.imshow("Video", imgStack)
예제 #5
0
                else:
                    objectType = "Rectangle"
            elif (objCor > 4):
                objectType = "Circle"
            else:
                objectType = "None"

            cv.rectangle(imgContour, (x, y), (w + x, h + y), (0, 0xff, 0), 2)
            cv.putText(imgContour, objectType,
                       (x + (w // 2) - 10, y + (h // 2) - 10),
                       cv.FONT_HERSHEY_COMPLEX, 0.5, (0, 0, 0), 2)


path = "/home/london/Pictures/OpenCV/shapes.png"
img = cv.imread(path)
imgContour = img.copy()
imgGray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
imgBlur = cv.GaussianBlur(imgGray, (7, 7), 1)
imgCanny = cv.Canny(imgBlur, 50, 50)
getContours(imgCanny)
imgBlank = np.zeros_like(img)

imgStack = stackImages(
    0.8, ([img, imgGray, imgBlur], [imgCanny, imgContour, imgBlank]))
cv.imshow("Stacked images", imgStack)
#cv.imshow("Original", img)
#cv.imshow("Grayed Image", imgGray)
#cv.imshow("Blurred Image", imgBlur)

while (cv.waitKey(1) != ord('q')):
    pass
    def start_track_bar(self):
        cv2.namedWindow("TrackBars")
        cv2.resizeWindow("TrackBars", 640, 240)
        cv2.createTrackbar("Hue Min", "TrackBars", 0, 179,
                           self.on_track_bar_change)
        cv2.createTrackbar("Hue Max", "TrackBars", 179, 179,
                           self.on_track_bar_change)
        cv2.createTrackbar("Sat Min", "TrackBars", 0, 255,
                           self.on_track_bar_change)
        cv2.createTrackbar("Sat Max", "TrackBars", 255, 255,
                           self.on_track_bar_change)
        cv2.createTrackbar("Val Min", "TrackBars", 0, 255,
                           self.on_track_bar_change)
        cv2.createTrackbar("Val Max", "TrackBars", 255, 255,
                           self.on_track_bar_change)

        image_camera_monde = cv2.imread("trajectory_example_3.jpg")

        GLARE_MIN = np.array([0, 0, 20], np.uint8)
        GLARE_MAX = np.array([0, 0, 255], np.uint8)

        hsv_img = cv2.cvtColor(image_camera_monde, cv2.COLOR_BGR2HSV)

        frame_threshed = cv2.inRange(hsv_img, GLARE_MIN, GLARE_MAX)

        result = cv2.inpaint(image_camera_monde, frame_threshed, 0.6,
                             cv2.INPAINT_TELEA)
        lab1 = cv2.cvtColor(result, cv2.COLOR_BGR2LAB)
        lab_planes1 = cv2.split(lab1)
        clahe1 = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8, 8))
        lab_planes1[0] = clahe1.apply(lab_planes1[0])
        lab1 = cv2.merge(lab_planes1)
        image = cv2.cvtColor(lab1, cv2.COLOR_LAB2BGR)

        imghsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV).astype("float32")
        (h, s, v) = cv2.split(imghsv)
        s = s * 2
        s = np.clip(s, 0, 255)
        imghsv = cv2.merge([h, s, v])

        image = cv2.cvtColor(imghsv.astype("uint8"), cv2.COLOR_HSV2BGR)

        hsvImg = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)

        hsvImg[..., 2] = hsvImg[..., 2] * 0.8
        image_camera_monde = cv2.cvtColor(hsvImg, cv2.COLOR_HSV2BGR)

        while True:
            hsv_image = cv2.cvtColor(image_camera_monde, cv2.COLOR_BGR2HSV)

            h_min = cv2.getTrackbarPos("Hue Min", "TrackBars")
            h_max = cv2.getTrackbarPos("Hue Max", "TrackBars")
            s_min = cv2.getTrackbarPos("Sat Min", "TrackBars")
            s_max = cv2.getTrackbarPos("Sat Max", "TrackBars")
            v_min = cv2.getTrackbarPos("Val Min", "TrackBars")
            v_max = cv2.getTrackbarPos("Val Max", "TrackBars")

            print(h_min, s_min, v_min, h_max, s_max, v_max)

            lower = np.array([h_min, s_min, v_min])
            upper = np.array([h_max, s_max, v_max])

            mask = cv2.inRange(hsv_image, lower, upper)

            image_result = cv2.bitwise_and(image_camera_monde,
                                           image_camera_monde,
                                           mask=mask)

            image_stack = stack_images.stackImages(
                0.6, ([image_camera_monde, hsv_image], [mask, image_result]))

            cv2.imshow("Image hsv", image_stack)

            cv2.waitKey(2000)
예제 #7
0
#Joining images
import cv2 as cv
import numpy as np
from stack_images import stackImages

img = cv.imread("/home/london/Pictures/OpenCV/train/cat.1.jpg")
img2 = cv.imread("/home/london/Pictures/OpenCV/train/cat.2.jpg")

imgGray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)

hor = np.hstack((img, img))
ver = np.vstack((img, img, img))

scaled = stackImages(0.5, ([img, img2]))

print(img.shape)
print(hor.shape)
print(ver.shape)

cv.imshow("Vertical", ver)
cv.imshow("Horizontal", hor)
cv.imshow("Original", img)
cv.imshow("Scaled", scaled)

while (not ((cv.waitKey(1) == ord('q')))):
    pass
예제 #8
0
cv.createTrackbar("Sat Max", "TrackBars", 255, 255, empty)

cv.createTrackbar("Val Min", "TrackBars", 114, 255, empty)
cv.createTrackbar("Val Max", "TrackBars", 255, 255, empty)

imgHSV = cv.cvtColor(img, cv.COLOR_BGR2HSV)

while (cv.waitKey(1) != ord('q')):
    h_min = cv.getTrackbarPos("Hue Min", "TrackBars")
    h_max = cv.getTrackbarPos("Hue Max", "TrackBars")

    s_min = cv.getTrackbarPos("Sat Min", "TrackBars")
    s_max = cv.getTrackbarPos("Sat Max", "TrackBars")

    v_min = cv.getTrackbarPos("Val Min", "TrackBars")
    v_max = cv.getTrackbarPos("Val Max", "TrackBars")

    lower = np.array([h_min, s_min, v_min])
    upper = np.array([h_max, s_max, v_max])
    mask = cv.inRange(imgHSV, lower, upper)

    imgRes = cv.bitwise_and(img, img, mask=mask)

    cv.imshow("Original", img)
    #cv.imshow("HSV", imgHSV)
    #cv.imshow("Mask", mask)
    #cv.imshow("Result", imgRes)

    imgStack = stackImages(0.6, ([img, imgHSV], [mask, imgRes]))
    cv.imshow("Stacked images", imgStack)