Εδώ βλέπετε τις διαφορές μεταξύ της επιλεγμένης έκδοσης και της τρέχουσας έκδοσης της σελίδας.
opencv [2020/02/23 12:39] John_Crabs |
opencv [2020/11/21 09:52] |
||
---|---|---|---|
Γραμμή 1: | Γραμμή 1: | ||
- | Μια μικρή εισαγωγή στην OpenCV ξεκινάει πάντα από ένα νέο λήμμα σε γουίκι... τον σύγχρονο τρόπο να μοιράζεσαι γνώση. | ||
- | Όσοι οι πιστοί προσέλθετε :-) | ||
- | |||
- | ====== Εισαγωγή στην OpenCV ====== | ||
- | |||
- | ====Τι είναι η OpenCV==== | ||
- | |||
- | Η OpenCV(Open-source Computer Vision) είναι μία βιβλιοθήκη που περιέχει συναρτήσεις, | ||
- | |||
- | Επίσης η OpenCV υποστηρίζει συστήματα Deep Learning, όπως είναι το TensorFlow, Torch/ | ||
- | |||
- | |||
- | ====Βασικές εφαρμογές της OpenCV==== | ||
- | |||
- | Όπως και με κάθε άλλη γλώσσα προγραμματισμού, | ||
- | |||
- | Ας ξεκινήσουμε λοιπόν. | ||
- | |||
- | ===Αλλαγή φωτεινότητας=== | ||
- | |||
- | import os | ||
- | import cv2 as cv | ||
- | import numpy as np | ||
- | import datetime as dt | ||
- | | ||
- | imgFileFormats = (" | ||
- | | ||
- | def checkImgFileType(src: | ||
- | typeIMG = None | ||
- | for f in imgFileFormats: | ||
- | if f in src: | ||
- | typeIMG = f | ||
- | return typeIMG | ||
- | | ||
- | def brightnessContrastChange(src: | ||
- | print(" | ||
- | print(str(dt.datetime.now()) + " : Read image file at %s" % src) | ||
- | img = cv.imread(src) | ||
- | | ||
- | # Check if image was opened correctly | ||
- | if img is None: | ||
- | print(str(dt.datetime.now()) + " | ||
- | return False, None | ||
- | | ||
- | newImg = np.zeros(img.shape, | ||
- | | ||
- | # Do the operation newImg(i,j) = contrastVal * img(i,j) + brightnessVal | ||
- | # Instead of these ' | ||
- | # newImg = cv.convertScaleAbs(image, | ||
- | # I prefer this method, cause it shows how to access the points of the image directly. This method can be used | ||
- | # if someone wants to write his own image manipulate functions | ||
- | for y in range(img.shape[0]): | ||
- | for x in range(img.shape[1]): | ||
- | for c in range(img.shape[2]): | ||
- | newImg[y, x, c] = np.clip(contrastVal * img[y, x, c] + brightnessVal, | ||
- | | ||
- | # newImg = cv.convertScaleAbs(image, | ||
- | | ||
- | if exportFolderPath is not None: # Check if an export path has need set | ||
- | if exportImageName is None: # Check if user has not specify a name | ||
- | exportImageName = os.path.splitext(os.path.basename(src))[0] | ||
- | exportImageName = exportImageName + " | ||
- | imgTypeFormat = os.path.splitext(os.path.basename(src))[1] | ||
- | else: | ||
- | imgTypeFormat = checkImgFileType(exportImageName) | ||
- | exportImageName = os.path.splitext(os.path.basename(exportImageName))[0] | ||
- | if imgTypeFormat is None: # If user hasn't specify a type then export image as JPG | ||
- | imgTypeFormat = " | ||
- | exportAt = exportFolderPath+exportImageName+imgTypeFormat | ||
- | print(str(dt.datetime.now()) + " : Write image file at %s" % exportAt) | ||
- | cv.imwrite(exportAt, | ||
- | | ||
- | return True, newImg |