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 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 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 onMouse(event, x, y, flags, userdata): global mouseClicks, image, windowName, imagePath 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 for i in range(0, 3): cv2.line(img=image, pt1=(src[i][0], src[i][1]), pt2=(src[i + 1][0], src[i + 1][1]), color=(0, 0, 255), thickness=10) cv2.line(img=image, pt1=(src[3][0], src[3][1]), pt2=(src[0][0], src[0][1]), color=(0, 0, 255), thickness=10) print(filename, end='') for point in src: print(f" ({point[0]}, {point[1]}) ", end='') print("\n") cv2.imwrite(highgui.getSavePath(imagePath, 'e'), image) out = [imagePath, src[0], src[1], src[2], src[3]] config = Path('GT.txt') if config.is_file() == False: config.touch() pickled = [] pickled.append(out) with open('GT.txt', 'wb') as f: pickle.dump(pickled, f) else: pickled = [] with open('GT.txt', 'rb') as f: pickled = pickle.load(f) pickled.append(out) with open('GT.txt', 'wb') as f: pickle.dump(pickled, f)
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}")
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 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 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'))