Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
projects:plate [2022/05/13 23:00] – old revision restored (2022/02/14 09:29) 216.244.66.228 | projects:plate [2022/06/20 14:19] (current) – old revision restored (2022/03/12 21:34) 154.54.249.201 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== | + | ====== |
- | * https:// | + | < |
+ | git clone https:// | ||
+ | </ | ||
+ | <file python convert.py> | ||
+ | import os | ||
+ | from os import walk, getcwd | ||
+ | from PIL import Image | ||
- | ===== install | + | classes |
- | ==== darknet | + | def convert(size, |
+ | dw = 1./ | ||
+ | dh = 1./ | ||
+ | x = (box[0] + box[1])/ | ||
+ | y = (box[2] + box[3])/ | ||
+ | w = box[1] - box[0] | ||
+ | h = box[3] - box[2] | ||
+ | x = x*dw | ||
+ | w = w*dw | ||
+ | y = y*dh | ||
+ | h = h*dh | ||
+ | return (x,y,w,h) | ||
+ | |||
+ | |||
+ | """ | ||
- | install | + | """ |
- | < | + | mypath = " |
+ | outpath = " | ||
- | </ | ||
- | ==== bbox (optional) ==== | + | cls = " |
- | ===== old ===== | + | wd = getcwd() |
+ | list_file | ||
+ | """ | ||
+ | txt_name_list = [] | ||
+ | for (dirpath, dirnames, filenames) in walk(mypath): | ||
+ | print(filenames) | ||
+ | txt_name_list.extend(filenames) | ||
+ | break | ||
+ | print(txt_name_list) | ||
- | plate detection with neural network | + | """ |
- | * https://matthewearl.github.io/ | + | for txt_name in txt_name_list: |
- | * https://github.com/matthewearl/deep-anpr | + | # txt_file = open(" |
+ | |||
+ | """ | ||
+ | txt_path = mypath + txt_name | ||
+ | print(" | ||
+ | txt_file = open(txt_path, | ||
+ | lines = txt_file.read().split(' | ||
+ | |||
+ | """ | ||
+ | txt_outpath = outpath + txt_name | ||
+ | print(" | ||
+ | txt_outfile = open(txt_outpath, | ||
+ | |||
+ | |||
+ | """ | ||
+ | ct = 0 | ||
+ | for line in lines: | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | if(len(line) >= 2): | ||
+ | ct = ct + 1 | ||
+ | print(line + " | ||
+ | elems = line.split(' | ||
+ | print(elems) | ||
+ | cls_id = elems[0].split(' | ||
+ | xmin = elems[0].split(' | ||
+ | xmax = elems[2] | ||
+ | ymin = elems[1] | ||
+ | ymax = elems[3][: | ||
+ | # | ||
+ | img_path = str(' | ||
+ | #t = magic.from_file(img_path) | ||
+ | #wh= re.search(' | ||
+ | im=Image.open(img_path) | ||
+ | w= int(im.size[0]) | ||
+ | h= int(im.size[1]) | ||
+ | #w = int(xmax) | ||
+ | #h = int(ymax) - int(ymin) | ||
+ | # print(xmin) | ||
+ | print(w, h) | ||
+ | b = (float(xmin), | ||
+ | bb = convert((w, | ||
+ | print(bb) | ||
+ | txt_outfile.write(str(cls_id) + " " + " " | ||
- | http://www.pyimagesearch.com/2017/02/13/ | + | """ |
- | <code python> | + | if(ct != 0): |
- | # load the example image | + | list_file.write(' |
- | image = cv2.imread(" | + | |
- | + | list_file.close() | |
- | # pre-process the image by resizing it, converting it to | + | </ |
- | # graycale, blurring it, and computing an edge map | + | |
- | image = imutils.resize(image, | + | |
- | gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) | + | |
- | # Applying Gaussian blurring with a 5×5 kernel to reduce high-frequency noise | + | |
- | blurred = cv2.GaussianBlur(gray, (5, 5), 0) | + | |
- | # Computing the edge map via the Canny edge detector. | ||
- | edged = cv2.Canny(blurred, | ||
- | # find contours in the edge map, then sort them by their | + | Train.txt Text.txt |
- | # size in descending order | + | |
- | cnts = cv2.findContours(edged.copy(), cv2.RETR_EXTERNAL, | + | |
- | cv2.CHAIN_APPROX_SIMPLE) | + | |
- | cnts = cnts[0] if imutils.is_cv2() else cnts[1] | + | |
- | cnts = sorted(cnts, | + | |
- | displayCnt = None | + | |
- | + | ||
- | # loop over the contours | + | |
- | for c in cnts: | + | |
- | # approximate the contour | + | |
- | peri = cv2.arcLength(c, | + | |
- | approx = cv2.approxPolyDP(c, | + | |
- | + | ||
- | # if the contour has four vertices, then we have found | + | |
- | # the thermostat display | + | |
- | if len(approx) == 4: | + | |
- | displayCnt = approx | + | |
- | break | + | |
- | # extract the plate, apply a perspective transform to it | ||
- | # Applying this perspective transform gives us a top-down, birds-eye-view of plate | ||
- | warped = four_point_transform(gray, | ||
- | output = four_point_transform(image, | ||
- | # threshold the warped image, then apply a series of morphological | + | <file python process.py> |
- | # operations to cleanup the thresholded image | + | import glob, os |
- | thresh = cv2.threshold(warped, | + | |
- | cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)[1] | + | |
- | kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, | + | |
- | thresh = cv2.morphologyEx(thresh, | + | |
- | # find contours in the thresholded image, then initialize the | + | # Current directory |
- | # digit contours lists | + | current_dir |
- | cnts = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL, | + | |
- | cv2.CHAIN_APPROX_SIMPLE) | + | |
- | cnts = cnts[0] if imutils.is_cv2() else cnts[1] | + | |
- | digitCnts = [] | + | |
- | + | ||
- | # loop over the digit area candidates | + | |
- | for c in cnts: | + | |
- | # compute the bounding box of the contour | + | |
- | (x, y, w, h) = cv2.boundingRect(c) | + | |
- | + | ||
- | # if the contour is sufficiently large, it must be a digit | + | |
- | if w >= 15 and (h >= 30 and h <= 40): | + | |
- | digitCnts.append(c) | + | |
- | # TODO display contour | + | # Directory where the data will reside, relative to ' |
- | # cv2.rectangle(output, | + | path_data = ' |
+ | # Percentage of images to be used for the test set | ||
+ | percentage_test = 10; | ||
- | # sort the contours from left-to-right, | + | # Create and/or truncate train.txt and test.txt |
- | # actual digits themselves | + | file_train |
- | digitCnts | + | file_test |
- | method=" | + | |
- | digits | + | |
- | # cv2.putText(output, | + | # Populate train.txt and test.txt |
- | # | + | counter = 1 |
+ | index_test = round(100 / percentage_test) | ||
+ | for pathAndFilename in glob.iglob(os.path.join(current_dir, " | ||
+ | title, ext = os.path.splitext(os.path.basename(pathAndFilename)) | ||
+ | if counter == index_test: | ||
+ | counter = 1 | ||
+ | file_test.write(path_data + title + ' | ||
+ | else: | ||
+ | file_train.write(path_data + title + ' | ||
+ | counter = counter + 1 | ||
+ | </ | ||
+ | |||
+ | Put images inside BBox-Label-Tool/ | ||
+ | convert to JPEG and delete old images | ||
+ | < | ||
+ | mogrify -format JPEG *.jpg | ||
+ | rm *.jpg | ||
</ | </ | ||
+ | |||
+ | Go to main folder and run python main.py | ||
+ | < | ||
+ | python main.py | ||
+ | </ | ||
+ | |||
+ | Write 001 inside Image Dir box and load | ||
+ | |||
+ | Create a label for each image | ||
+ | |||
+ | After that, exit and create a new directory inside Label | ||
+ | < | ||
+ | mkdir output | ||
+ | </ | ||
+ | Run convert.py | ||
+ | < | ||
+ | python convert.py | ||
+ | </ | ||
+ | |||
+ | Now create test.txt and train.txt with process.py | ||
+ | < | ||
+ | python process.py | ||
+ | </ | ||
+ | < | ||
+ | ├── Images (input) | ||
+ | │ | ||
+ | │ | ||
+ | │ | ||
+ | ├── Labels (output) | ||
+ | │ | ||
+ | │ | ||
+ | │ | ||
+ | │ | ||
+ | </ | ||
+ | ====== Darknet ====== | ||
+ | < | ||
+ | git clone https:// | ||
+ | cd darknet | ||
+ | make | ||
+ | </ | ||
+ | |||
+ | Copy train.txt and test.txt inside darknet/ | ||
+ | |||
+ | Create 3 files: | ||
+ | obj.data | ||
+ | obj.names | ||
+ | obj.cfg | ||
+ | |||
+ | <file obj.data> | ||
+ | classes= *NUMBER CLASSES* | ||
+ | train = *TRAIN DIRECTORY+ | ||
+ | valid = *TEST DIRECTORY* | ||
+ | names = obj.names | ||
+ | backup = *BACKUP FOLDER* | ||
+ | </ | ||
+ | |||
+ | <file obj.names> | ||
+ | *CLASS NAME* | ||
+ | </ | ||
+ | |||
+ | Copy yolov2-tiny.cfg and change [region]: | ||
+ | classes = *NUMBER CLASSES* | ||
+ | filters = (*NUMBER CLASSES* +5)*5 | ||
+ | |||
+ | |||
+ |