forked from leenachennuru/objRecognition
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsegmentationNew.py
61 lines (51 loc) · 2.22 KB
/
segmentationNew.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# -*- coding: utf-8 -*-
"""
Created on Thu Dec 3 17:07:00 2015
@author: 4wahab
"""
import numpy as np
import cv2
from matplotlib import pyplot as plt
import preObj as prePro
import detectorDescriptor as detDes
import glob
rootInputName = "TrainingSet/TrainingData/objectRecognitionDatasetKinect/"
rootOutputName = "TrainingSet/newDatasetPrep/contours/"
rootMeanName = "TrainingSet/newDatasetPrep/meanShift/"
rootAdapThreshold = "TrainingSet/newDatasetPrep/adapThreshold/"
rootContourDraw = "TrainingSet/newDatasetPrep/contourDraw/"
formatName = "*.jpg"
fileList = glob.glob(rootInputName + formatName)
print ("Current Directory Name:" + rootInputName)
count = 0
for files in fileList:
inputImage=cv2.imread(fileList[count])
fileName = os.path.basename(fileList[count])
print ("Processing Image " + fileList[count])
grayScaleInput = cv2.cvtColor(inputImage, cv2.COLOR_BGR2GRAY)
meanShiftResult = prePro.meanShift(inputImage)
cv2.imwrite(rootMeanName + fileName, meanShiftResult)
meanShiftGray = cv2.cvtColor(meanShiftResult, cv2.COLOR_BGR2GRAY)
meanShiftAdapResult = prePro.adapThresh(meanShiftGray)
cv2.imwrite(rootAdapThreshold + fileName, meanShiftAdapResult)
contourPlot = prePro.contourDraw(inputImage, meanShiftAdapResult)
cv2.imwrite(rootContourDraw + fileName, contourPlot)
print ("Preprocessing Results Written.")
contours, hierarchy = prePro.contourFindFull(meanShiftAdapResult)
boundBoxContour = grayScaleInput.copy()
counter = 0
for cnt in contours:
if cv2.contourArea(cnt)>20:
print("Processing Contour no.", str(counter))
[x, y, w, h] = cv2.boundingRect(cnt)
extendBBox = 5
roiImage = boundBoxContour[y-extendBBox:y+h+extendBBox, x-extendBBox:x+w+extendBBox]
roiImageFiltered = roiImage #cv2.medianBlur(roiImage, 3)
kp, roiKeyPointImage = detDes.featureDetectCorner(roiImageFiltered)
kp, des, roiKeyPointImage = detDes.featureDescriptorORB(roiImageFiltered, kp)
if np.size(kp)>0:
cv2.imwrite(rootOutputName + str(count*1000 + counter*10) + ".png", roiImage)
print ("Path: " + rootOutputName + str(count*100 + counter*10) + ".png")
print ("Found some non-zero keypoints for the countours.")
counter = counter + 1
count = count + 1