def main(): imagePath = optcheck.getArguments()[0] image = highgui.openImage(imagePath) image = imgproc.detectLines(image, 100, 200) highgui.showImage("name", image) highgui.saveImage(image, highgui.getSavePath(imagePath, '11'))
def main(): (image1_path, image2_path) = optcheck.getArguments() image1 = highgui.openImage(image1_path) image2 = highgui.openImage(image2_path) imgproc.detectORBFeatures(image1, 96) imgproc.detectORBFeatures(image2, 96) matches = imgproc.matchORBFeatures(image1, image2, 96, 48) highgui.showImagesHorizontally("ORB feature detection", matches) highgui.saveImage(matches, 'Images\matchesEX13.png')
def main(): (image1_path, image2_path) = optcheck.getArguments() image1 = highgui.openImage(image1_path) image2 = highgui.openImage(image2_path) imgproc.detectCorners(image1) imgproc.detectCorners(image2) highgui.showImagesHorizontally("Corner feature detection", image1, image2) highgui.saveImage(image1, highgui.getSavePath(image1_path, '12')) highgui.saveImage(image2, highgui.getSavePath(image2_path, '12'))
def onMouse(event, x, y, flags, userdata): global mouseClicks, image, windowName print("sure buddy") if (cv2.EVENT_LBUTTONDOWN == event and mouseClicks < 4): src[mouseClicks] = [x, y] mouseClicks += 1 if (mouseClicks == 4): mouseClicks += 1 # increase one more time so this function will basically do nothing anymore M = cv2.getPerspectiveTransform(src, dst) # Get the transformation matrix warped = cv2.warpPerspective(image, M, (-1, -1)) # warp the image result = cv2.hconcat( (image, warped)) # concatenate the original image and warped image cv2.imshow(windowName, result) # show original and warped image # Saving the warped image highgui.saveImage(warped, highgui.getSavePath(imagepath, '9'))
def evaluateClassifierPerformance(classifier): avg_precision = 0 avg_recall = 0 # apply 4-fold cross validation: image with index i will be used as testdata, the other images as trainingdata for i in range(1, len(IMAGES) + 1): trainingSet = IMAGES[:i - 1] + IMAGES[i:] testImage = IMAGES[i - 1] featureSet = [] labelSet = [] for imagePath in trainingSet: image = highgui.openImage(f"{imagePath}.png") image_blocks = highgui.openImage(f"{imagePath}_blocks.png") features = getFeatureVectors(image) labels = getRoadMarkings(image_blocks) (features, labels) = balanceTrainingset(features, labels) featureSet.extend(features) labelSet.extend(labels) classifier.fit(featureSet, labelSet) image = highgui.openImage(f"{testImage}.png") image_blocks = highgui.openImage(f"{testImage}_blocks.png") predictions = classifier.predict(getFeatureVectors(image)) groundTruth = getRoadMarkings(image_blocks) # visualize the filter means visualizeMeans(getFeatureVectors(image), groundTruth, f"{IMAGES[i - 1]}_filter.png") predictionImage = getOverlayedImage(image, predictions) highgui.saveImage( predictionImage, highgui.getSavePath(f"{testImage}.png", 'CLASSIFIER')) TP, FP, FN, TN = (0, 0, 0, 0) for prediction, groundTruth in zip(predictions, groundTruth): if (groundTruth == 1): if (prediction == 1): TP += 1 else: FN += 1 elif (groundTruth == 0): if (prediction == 1): FP += 1 else: TN += 1 precision = round( TP / (TP + FP), 4 ) * 100 # given a positive prediction from the classifier, how likely is it to be correct? recall = round( TP / (TP + FN), 4 ) * 100 # given a positive example, will the classifier detect it? avg_precision += precision avg_recall += recall #print(f"road{i} & {precision}\\% & {recall}\\% \\\\") # for latex print( f"recall and precision considering {trainingSet} as the training data and {testImage} as the test data" ) print(f"Precision: {precision} \t Recall: {recall}")
import cv2 import sys import os.path import numpy from Modules import optcheck, highgui, imgproc #blots.png fullPath = optcheck.getArguments()[0] filepath, filename = os.path.split(fullPath) cv2.namedWindow(filename) image = cv2.imread(fullPath) size = 15 kernel = numpy.zeros( (size, size)) # de matrix zal de figuur uitsmeren naar rechtsonder for i in range(0, 7): kernel[i][i] = 1 / 7 filteredImage = cv2.imread(fullPath) cv2.filter2D(image, -1, kernel, filteredImage, (size - 1, size - 1)) highgui.showImagesHorizontally(filename, image, filteredImage) filename, extension = filename.split(".") savePath = filepath + "\\" + filename + "EX6." + extension highgui.saveImage(filteredImage, savePath)
def main(): imagePath = optcheck.getArguments()[0] image = highgui.openImage(imagePath) result = imgproc.extractEdges(image, -15) highgui.showImage(imagePath, result) highgui.saveImage(result, highgui.getSavePath(imagePath, '10'))
import cv2 import sys import os.path from Modules import highgui, imgproc, optcheck #building.png fullPath = optcheck.getArguments()[0] filepath, filename = os.path.split(fullPath) cv2.namedWindow(filename) image = cv2.imread(fullPath) grayScaleImage = imgproc.convertToGrayscale(image) sobelImage = cv2.Sobel(grayScaleImage, -1, 0, 1) highgui.showImagesHorizontally(filename, grayScaleImage, sobelImage) filename, extension = filename.split(".") savePath = filepath + "\\" + filename + "EX5." + extension highgui.saveImage(sobelImage, savePath)
import cv2 from Modules import optcheck, highgui, imgproc #rainbowdiscs.png imagePath = optcheck.getArguments()[0] image = highgui.openImage(imagePath) D = cv2.getStructuringElement(cv2.MORPH_RECT, (1, 5)) dilation = cv2.dilate(image, D, iterations=3) E = cv2.getStructuringElement(cv2.MORPH_RECT, (3, 3)) erosion = cv2.erode(dilation, E, iterations=3) highgui.showImagesHorizontally("EX7", image, dilation, erosion) highgui.saveImage(erosion, highgui.getSavePath(imagePath, '7EROSION')) highgui.saveImage(dilation, highgui.getSavePath(imagePath, '7DILATION'))
import cv2 import os from Modules import optcheck, highgui #whitenoise.png fullPath = optcheck.getArguments()[0] filepath, filename = os.path.split(fullPath) cv2.namedWindow(filename) image = cv2.imread(fullPath) gaussianBlurredImage = cv2.GaussianBlur(image, (5, 5), 3) highgui.showImagesHorizontally(filename, image, gaussianBlurredImage) filename, extension = filename.split(".") savePath = filepath + "\\" + filename + "EX2." + extension highgui.saveImage(gaussianBlurredImage, savePath)
import cv2 import sys import os.path from Modules import optcheck, highgui #saltandpeppernoise.png fullPath = optcheck.getArguments()[0] filepath, filename = os.path.split(fullPath) cv2.namedWindow(filename) image = cv2.imread(fullPath) medianBlurredImage = cv2.medianBlur(image, 3) highgui.showImagesHorizontally(filename, image, medianBlurredImage) filename, extension = filename.split(".") savePath = filepath + "\\" + filename + "EX4." + extension highgui.saveImage(medianBlurredImage, savePath)
import cv2 import numpy from Modules import optcheck, highgui, imgproc #shadow.png imagepath = optcheck.getArguments()[0] image = highgui.openImage(imagepath) shear_factor = -0.2 M = numpy.float32([[1, shear_factor, 50], [0, 1, 0]]) shearImage = cv2.warpAffine(image, M, (-1, -1)) highgui.showImagesHorizontally("Shearing", image, shearImage) highgui.saveImage(shearImage, highgui.getSavePath(imagepath, '8'))