From 420c1004098263eb272b163bf6ae40f81992a433 Mon Sep 17 00:00:00 2001 From: Auzan Muhammad Date: Mon, 14 Nov 2016 15:19:19 +0700 Subject: [PATCH 1/2] Delete shadow_removal.py --- shadow_removal.py | 82 ----------------------------------------------- 1 file changed, 82 deletions(-) delete mode 100644 shadow_removal.py diff --git a/shadow_removal.py b/shadow_removal.py deleted file mode 100644 index 80111b9..0000000 --- a/shadow_removal.py +++ /dev/null @@ -1,82 +0,0 @@ -import cv2 -import numpy as np - -def hsvPassShadowRemoval(src, shadowThreshold): - blurLevel = 3 - height, width = src.shape[:2] - imgHSV = cv2.cvtColor(src, cv2.COLOR_RGB2HSV) - gaussianBlur = cv2.GaussianBlur(imgHSV, (blurLevel, blurLevel), 0) - hueImg, satImg, valImg = cv2.split(gaussianBlur) - - NSVDI = np.zeros((height, width, 1), np.uint8) - count = height * width - with np.errstate(divide='ignore'): - # for i in range(0, height): - # for j in range(0, width): - # sat = int(satImg[i, j]) - # val = int(valImg[i, j]) - # NSVDI[i, j] = (satImg[i, j] - valImg[i, j]) / ((satImg[i, j] + valImg[i, j]) * 1.0) - NSVDI = (satImg + valImg) / ((satImg - valImg) * 1) - thresh = np.sum(NSVDI) - avg = thresh / (count * 1.0) - - # for i in range(0, height): - # for j in range(0, width): - # if NSVDI[i, j] >= 0.25: - # hueImg[i, j] = 255 - # satImg[i, j] = 255 - # valImg[i, j] = 255 - # else: - # hueImg[i, j] = 0 - # satImg[i, j] = 0 - # valImg[i, j] = 0 - - if shadowThreshold is None: - avg = avg - else: - avg = shadowThreshold - - np.where(NSVDI > avg, 255, 0) - _, threshold = cv2.threshold(NSVDI, avg, 255, cv2.THRESH_BINARY_INV) - - output = threshold - return output - -def yuvPassShadowRemoval(src, shadowThreshold): - height, width = src.shape[:2] - imgYUV = cv2.cvtColor(src, cv2.COLOR_RGB2YUV) - yImg, uImg, vImg = cv2.split(imgYUV) - - # for i in range(0, height): - # for j in range(0, width): - # yImg[i, j] = 0 - yImg = np.zeros((height, width, 1), np.uint8) - imgYUV = cv2.merge([yImg, uImg, vImg]) - - rgbImg = cv2.cvtColor(imgYUV, cv2.COLOR_YUV2RGB) - rImg, gImg, bImg = cv2.split(rgbImg) - - count = width * height - avg = np.sum(bImg) - avg /= count * 1.0 - # for i in range(0, height): - # for j in range(0, width): - # if bImg[i, j] > ave: - # rImg[i, j] = 255 - # gImg[i, j] = 255 - # bImg[i, j] = 255 - # else: - # rImg[i, j] = 0 - # gImg[i, j] = 0 - # bImg[i, j] = 0 - - if shadowThreshold is None: - avg = avg - else: - avg = shadowThreshold - - np.where(bImg > avg, 255, 0) - _, threshold = cv2.threshold(bImg, avg, 255, cv2.THRESH_BINARY) - - output = threshold - return output \ No newline at end of file From eca9e072ac8aea07e25ecc167be3b2ba6a14c166 Mon Sep 17 00:00:00 2001 From: Auzan Muhammad Date: Mon, 14 Nov 2016 15:19:40 +0700 Subject: [PATCH 2/2] Delete math_operation.py --- math_operation.py | 202 ---------------------------------------------- 1 file changed, 202 deletions(-) delete mode 100644 math_operation.py diff --git a/math_operation.py b/math_operation.py deleted file mode 100644 index a8106fd..0000000 --- a/math_operation.py +++ /dev/null @@ -1,202 +0,0 @@ -import math - -def centeroidPinHoleMode(height, focal, altitude, theta, yCoordinate): - # height : jumlah baris (piksel) - # focal -> |A'O| : focal length (piksel) - # altitude -> |O'O| : tinggi kamera (m) - # theta : sudut kemiringan kamera (derajat) - # yCoordinate : indeks piksel Y object - height = float(height) - focal = float(focal) - theta = float(theta) - yCoordinate = float(yCoordinate) - - delta = math.degrees(math.atan(math.fabs(yCoordinate - (height / 2)) / focal)) - - if yCoordinate >= height / 2: - lCentroid = altitude * math.tan(math.radians(theta + delta)) - else: - lCentroid = altitude * math.tan(math.radians(theta - delta)) - - lCentroid = round(lCentroid, 4) - delta = round(delta, 4) - - # print "delta: {0} | lCentroid: {1}".format(delta, lCentroid) - return lCentroid - -def vertikalPinHoleModel(height, focal, altitude, theta, y1, y2, maxHighLV, maxHighHV, maxLengthLV): - # height : jumlah baris (piksel) - # focal -> |A'O| : focal length (piksel) - # altitude -> |O'O| : tinggi kamera (m) - # theta : sudut kemiringan kamera (derajat) - # y1' : indeks piksel terdepan kendaraan (kordinat y) - # y2' : indeks piksel terbelakang kendaraan (kordinat y) - # Ly1 -> |O'X1| : jarak titik terdepan kendaraan dengan kamera (m) - # Ly2 -> |O'X2| : jarak titik blindspot belakang kendaraan (m) - # Y2G -> |Y2G| : jarak belakang kendaraan dengan titik blindspot belakang kendaraan (m) - - delta1 = math.degrees(math.atan(math.fabs((height / 2) - y1) / focal)) - delta2 = math.degrees(math.atan(math.fabs((height / 2) - y2) / focal)) - - if y1 >= height / 2: - Ly1 = altitude * math.tan(math.radians(theta + delta1)) - else: - Ly1 = altitude * math.tan(math.radians(theta - delta1)) - - if y2 >= height / 2: - Ly2 = altitude * math.tan(math.radians(theta + delta2)) - else: - Ly2 = altitude * math.tan(math.radians(theta - delta2)) - - Lv = math.fabs(Ly1 - Ly2) - - if y2 >= height / 2: - Y2G_LV = maxHighLV * math.tan(math.radians(theta + delta2)) - Y2G_HV = maxHighHV * math.tan(math.radians(theta + delta2)) - else: - Y2G_LV = maxHighLV * math.tan(math.radians(theta - delta2)) - Y2G_HV = maxHighHV * math.tan(math.radians(theta - delta2)) - - LengthLV = (Ly2 - (Ly1 + Y2G_LV)) - LengthHV = (Ly2 - (Ly1 + Y2G_HV)) - - if LengthLV <= maxLengthLV: - Lv = LengthLV - else: - Lv = LengthLV - - #Lv = Ly2 - Ly1 - - delta1 = round(delta1, 3) - delta2 = round(delta2, 3) - Ly1 = round(Ly1, 4) - Ly2 = round(Ly2, 4) - Y2G_LV = round(Y2G_LV, 4) - Y2G_HV = round(Y2G_HV, 4) - Lv = round(Lv, 3) - - # print "delta1: {0} | delta2: {1} | Lx1: {2} | Lx2: {3} | X2GLV: {4} | X2GHVC: {5}| Lv: {6}".format(delta1, delta2, Lx1, Lx2, X2GLV, X2GHV, Lv) - return Lv - -def horizontalPinHoleModel(width, focal, altitude, x1, x2, lengthObject): - # width : jumlah kolom (piksel) - # focal -> |A'O| : focal length (piksel) - # altitude -> |O'O| : tinggi kamera (m) - # theta : sudut kemiringan kamera (derajat) - # lengthObject : jarak objek dengan kamera (m) - # x1' : indeks piksel kanan kendaraan (kordinat x) - # x2' : indeks piksel kiri kendaraan (kordinat x) - # Lw1 -> |O'X1| : jarak titik kanan kendaraan dengan titik tengah kamera (m) - # Lw2 -> |O'X2| : jarak titik kiri kendaraan dengan titik tengah kamera (m) - # X2G -> |X2G| : jarak belakang kendaraan dengan titik blindspot belakang kendaraan (m) - - delta1 = math.degrees(math.atan(math.fabs(x1 - (width / 2)) / focal)) - delta2 = math.degrees(math.atan(math.fabs(x2 - (width / 2)) / focal)) - - OX = math.sqrt(math.pow(lengthObject, 2) + math.pow(altitude, 2)) - - Lx1 = math.tan(math.radians(delta1)) * OX - Lx2 = math.tan(math.radians(delta2)) * OX - - if (x1 <= width / 2) and (x2 >= width / 2): - Lx = round((Lx2 + Lx1), 3) - else: - Lx = round(math.fabs(Lx2 - Lx1), 3) - - delta1 = round(delta1, 3) - delta2 = round(delta2, 3) - lengthObject = round(lengthObject, 2) - OX = round(OX, 4) - Lx1 = round(Lx1, 4) - Lx2 = round(Lx2, 4) - - # print "delta1: {0} | delta2: {1} | Length: {2} | OX: {3} | Lw1: {4} | Lw2: {5} | widthObject: {6}".format(delta1, delta2, lengthObject, OX, Lw1, Lw2, Lw) - return Lx - -def funcY_line(x1, y1, x2, y2, X): - # m : line gradient - # y - y1 = m (x -x1) - # y = m (x - x1) + y - - x1 = float(x1) - y1 = float(y1) - x2 = float(x2) - y2 = float(y2) - X = float(X) - - m = (y1 - y2) / (x1 - x2) - Y = ((m * X) - (m * x1)) + y1 - Y = int(round(Y)) - return Y - -def funcX_line(x1, y1, x2, y2, Y): - # m : line gradient - # y - y1 = m (x -x1) - # x = ((y - y1) + (m * x1)) /m - - x1 = float(x1) - y1 = float(y1) - x2 = float(x2) - y2 = float(y2) - Y = float(Y) - - m = (y1 - y2) / (x1 - x2) - X = ((Y - y1) + (m * x1)) / m - X = int(round(X)) - return X - -def getFocalfromFOV(width, fov): - focal = (width / 2) / math.tan(math.radians(fov / 2)) - return focal - -def transformDiagonalFOV(fov): - if fov == 90.0: - horizontalFOV = 78.4 - verticalFOV = 44.1 - elif fov == 127.0: - horizontalFOV = 113.3 - verticalFOV = 63.7 - elif fov == 160.0: - horizontalFOV = 139.5 - verticalFOV = 78.4 - else: - horizontalFOV, verticalFOV = fov - - return horizontalFOV, verticalFOV - -def euclideanDistance(x1, y1, x2, y2): - x1 = float(x1) - y1 = float(y1) - x2 = float(x2) - y2 = float(y2) - - distance = math.sqrt((math.pow(math.fabs(x1 - x2), 2) + (math.pow(math.fabs(y1 - y2), 2)))) - distance = int(distance) - - return distance - -def determineCropFactor(sensorwidth, sensorheight): - # Comparison between 35mm lens - # FX : 35mm * 26mm sensor size - cropfactor = math.sqrt(math.pow(36, 2) + math.pow(24, 2)) / math.sqrt(math.pow(sensorheight, 2) + math.pow(sensorwidth, 2)) - - return cropfactor - -def getCoordinateFromDistance(height, focal, altitude, theta, distance): - # height : jumlah baris (piksel) - # focal : panjang focal length kamera (piksel) - # altitude : ketinggian kamera - # theta : kemiringan kamera - # distance : jarak yang ingin diketahui lokasinya - - distance = float(distance) - altitude = float(altitude) - focal = float(focal) - - alpha = math.degrees(math.atan(distance / altitude)) - delta = theta - alpha - yCoordinate = focal * math.tan(math.radians(delta)) - yCoordinate += (height / 2) - - # print "alpha: {0} | delta: {1}".format(alpha, delta) - return yCoordinate