def __main__(): while True: print("\nChoose an algorithm to sort with!") print("1: Bubble Sort") print("2: Insertion Sort") print("3: Selection Sort") print("4: Quick Sort") print("5: Shell Sort") choice = input("Use algorithm nr: ") if choice == "1": sorter = sorting("Bubble Sort") sorter.loop("bubble") elif choice == "2": sorter = sorting("Insertion Sort") sorter.loop("insertion") elif choice == "3": sorter = sorting("Selection Sort") sorter.loop("selection") elif choice == "4": sorter = sorting("Quick Sort") sorter.loop("quick") elif choice == "5": sorter = sorting("Shell Sort") sorter.loop("shell") else: print("Invalid choice!")
def contour(image_color): x = 800 image_color = cv2.resize(image_color, (x, int(x * 1.414))) roi = image_color[150:1050, 300:700] image_color = roi.copy() lower_bound = np.array([0, 0, 10]) upper_bound = np.array([255, 255, 195]) lower_bound = np.array([0, 0, 10]) upper_bound = np.array([255, 255, 195]) image = image_color mask = cv2.inRange(image_color, lower_bound, upper_bound) k = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3, 3)) closing = cv2.morphologyEx(mask, cv2.MORPH_OPEN, k) gradient = cv2.morphologyEx(mask, cv2.MORPH_GRADIENT, k) gBlur = cv2.GaussianBlur(mask, (13, 13), 2) # gBlur = cv2.GaussianBlur(mask, (13, 13), 2) mask = cv2.dilate(mask, k, iterations=1) mask = cv2.erode(mask, k, iterations=1) _, contours, hierarchy = cv2.findContours(mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) # contours = sorted(contours, key=lambda x: cv2.contourArea(x)) #does nothing rn contours = list( filter(lambda x: cv2.contourArea(x) < 250 and cv2.contourArea(x) > 180, contours)) good = [] for (i, c) in enumerate(contours): if (isUnique(image_color, c, i, contours)): # draw_contour1(image, c, i) good.append(c) good = sorting.sorting(good) for (i, c) in enumerate(good): draw_contour2(image, c, i) resize = cv2.drawContours(image_color, good, -1, (255, 0, 0), 1) cv2.imshow("resize", image_color) return good # other = cv2.imread("9.png") # ans.answers(other,good) # cv2.waitKey(0) # cv2.destroyAllWindows()
def getpos(image_color): # image_color= cv2.imread("boi.jpeg") # image_ori = cv2.cvtColor(image_color,cv2.COLOR_BGR2GRAY) x = 800 image_color = cv2.resize(image_color, (x, int(x * 1.414))) cv2.imwrite("boi.jpeg", image_color) sub_image = image_color[150:1030, 300:700] image_color = sub_image.copy() # sub_image = img[y:y+h, x:x+w] lower_bound = np.array([0, 0, 10]) upper_bound = np.array([255, 255, 195]) image = image_color mask = cv2.inRange(image_color, lower_bound, upper_bound) # mask = cv2.adaptiveThreshold(sub_image,255,cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY_INV,33,2) k = 3 kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3, 3)) #Use erosion and dilation combination to eliminate false positives. #In this case the text Q0X could be identified as circles but it is not. closing = cv2.morphologyEx(mask, cv2.MORPH_OPEN, kernel) gradient = cv2.morphologyEx(mask, cv2.MORPH_GRADIENT, kernel) gBlur = cv2.GaussianBlur(mask, (13, 13), 2) gBlur = cv2.GaussianBlur(mask, (13, 13), 2) mask = cv2.dilate(mask, kernel, iterations=1) # mask = cv2.erode(mask, kernel, iterations=1) # cv2.imshow("eroded1", mask) mask = cv2.erode(mask, kernel, iterations=1) _, contours, hierarchy = cv2.findContours(mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) contours = list( filter(lambda x: cv2.contourArea(x) < 250 and cv2.contourArea(x) > 155, contours)) srtdcontours = [] for (i, c) in enumerate(contours): if (isUnique(image_color, c, i, contours)): # draw_contour1(image, c, i) srtdcontours.append(c) srtdcontours = sorting.sorting(srtdcontours) for (i, c) in enumerate(srtdcontours): draw_contour2(image, c, i) resize = cv2.drawContours(image_color, srtdcontours, -1, (255, 0, 0), 1) cv2.imshow("resize", image_color) return srtdcontours
def makeWordFile(path, clipboard): # Make a new docs d = docx.Document() # Change style style = d.styles['Normal'] font = style.font font.name = 'Arial' #Sort clipboard if necessary clipboard = sorting.sorting(clipboard) # Add the string to the docs d.add_paragraph(clipboard) # Prompt user for name for new doc file name = input("New name for the file: ") # Saves the new document at the PATH new_path = os.path.join(path, name) new_path = new_path + ".docx" d.save(new_path)
def main(): """ This program akes an input file and sorts the file, counting the occurances of a word and eliminates the extra occurances so there is just one instance of the word into an ordered list at which point it will create a binary tree based on the information with each node containint the item, the number of times the item occurred in the text document, as well as the right and left children. It will then search the binary tree. """ #-------------------- opens text and sorts it into nested list ---------------# searching = search() #file_input = raw_input("Enter the name of your .txt file here: ") #file_input = 'FPinput.txt' #For ease of testing file_input = 'longer_input.txt' sort_of = sorting() well = sort_of.read_words(file_input) # for ease of testing #looking_for = raw_input("Enter the word you are looking for here: ") looking_for = 'input' #test word #-----------------------------------------------------------------------------# #------- Performs a linear search and times it before the file is sorted -----# print("--------------------------------------------------") print("The Linear Search will begin.") startLinear = time.time() searching.linear_search(looking_for, well) endLinear = time.time() timedLinear = endLinear - startLinear print("Your time for the Linear search was:") print timedLinear print("--------------------------------------------------") #-----------------------------------------------------------------------------# #-------------- Performs a binary search on the array and times it ------------# print("The Binary Search will begin.") startBinary = time.time() searching.binary_search(looking_for, well) endBinary = time.time() timedBinary = endBinary - startBinary print("Your time for the Binary search was:") print timedBinary print("--------------------------------------------------") #-----------------------------------------------------------------------------# #---------------------- creates binary tree ----------------------------------# print( "The following words have been sorted and counted, as indicated by the number beside them." ) file_array = sort_of.count_words(well) print("--------------------------------------------------") run = Node() run_forrest = BinaryTree() run.set_value(file_array[(len(file_array) / 2)]) print("The following values have been populated into a Binary Tree.") running = run_forrest.populate_from_array(run, file_array, len(file_array)) running print("--------------------------------------------------") #-----------------------------------------------------------------------------# #-------------- Performs a binary search on the tree and times it ------------# print("The Binary Tree Search will begin.") startBinaryST = time.time() run_forrest.binary_searchT(looking_for, run) endBinaryST = time.time() timedBinaryST = endBinaryST - startBinaryST print("Your time for the Binary search was:") print timedBinaryST print("--------------------------------------------------")
def testcase01(self): ori = [3, 1, 0, 7, 9, 12, 11] sorted = [0, 1, 3, 7, 9, 11, 12] self.assertEqual(sorting(ori), sorted)
def test_bubble_0(self): bubble = sorting() listamal = [66, 71, 16, 21, 79, 9, 40, 60, 5] listabien = bubble.bubbleSorting(listamal) self.assertEqual(listamal, [5, 9, 16, 21, 40, 60, 66, 71, 79])
def test_bubble_1(self): bubble = sorting() listamal = [0, 1, 77, 3, 77, 4, 77, 3, 2, 5] listabien = bubble.bubbleSorting(listamal) self.assertEqual(listabien, [0, 1, 2, 3, 3, 4, 5, 77, 77, 77])
from sorting import sorting import pandas as pd sorting(2, 'Article_더팩트40_.csv', 2, 'y', 'y')
# Data preprocess step save_model(bagging_iter=BAGGING_ITER, input_path=TRAIN_PATH) # MODEl train step YM_parser(BAGGING_ITER) else: prepare(bagging_iter=BAGGING_ITER, train_path=TRAIN_PATH, test_path=TEST_PATH,\ g_score=G_SCORE, a_score=A_SCORE, scope=SCOPE, mode=MODE) # Data preprocess step save_model(bagging_iter=BAGGING_ITER, input_path=TRAIN_PATH) # MODEl train step YM_parser(BAGGING_ITER) elif MODE == 'predict': # Data predict step predict(bagging_iter=BAGGING_ITER, input_path=TEST_PATH, mode=MODE) # #Weighted voting & CKY voting(bagging_iter=BAGGING_ITER, mode=MODE) # Prepare next bagging prepare(bagging_iter=BAGGING_ITER, train_path=TRAIN_PATH, test_path=TEST_PATH,\ g_score=G_SCORE, a_score=A_SCORE, scope=SCOPE, mode=MODE) elif MODE == 'g_predict': # Data predict step predict(bagging_iter=BAGGING_ITER, input_path=TEST_PATH, mode=MODE) # #Weighted voting & CKY voting(bagging_iter=BAGGING_ITER, mode=MODE) sorting(bagging_iter=BAGGING_ITER, output_path=OUTPUT_PATH, mode=MODE,\ g_score=G_SCORE, a_score=A_SCORE)
def contour(image_color): x = 800 image_color = cv2.resize(image_color, (x, int(x * 1.414))) roi = image_color[150:1050, 300:700] image_color = roi.copy() lower_bound = np.array([0, 0, 10]) upper_bound = np.array([255, 255, 195]) lower_bound = np.array([0, 0, 10]) upper_bound = np.array([255, 255, 195]) image = image_color mask = cv2.inRange(image_color, lower_bound, upper_bound) k = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3, 3)) closing = cv2.morphologyEx(mask, cv2.MORPH_OPEN, k) gradient = cv2.morphologyEx(mask, cv2.MORPH_GRADIENT, k) gBlur = cv2.GaussianBlur(mask, (13, 13), 2) gBlur = cv2.GaussianBlur(mask, (13, 13), 2) mask = cv2.dilate(mask, k, iterations=1) mask = cv2.erode(mask, k, iterations=1) _, contours, hierarchy = cv2.findContours(mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) # contours = sorted(contours, key=lambda x: cv2.contourArea(x)) #does nothing rn contours = list( filter(lambda x: cv2.contourArea(x) < 250 and cv2.contourArea(x) > 180, contours)) #alternate method for quality checking. Replace "contours" with "array" in drawContours call to use # array = [] # ii = 1 # print (len(contours)) # for c in contours: # (x,y),r = cv2.minEnclosingCircle(c) # center = (int(x),int(y)) # r = int(r) # if r >= 6 and r<=10: # cv2.circle(image,center,r,(0,255,0),2) # array.append(center) good = [] for (i, c) in enumerate(contours): if (isUnique(image_color, c, i, contours)): # draw_contour1(image, c, i) good.append(c) # else: # draw_contour2(image, c, i) # for (i, c) in enumerate(good): # draw_contour2(image, c, i) # cv2.imshow("resize", image_color) # cv2.waitKey(0) # resize = cv2.drawContours(image_color, good, -1, (255,0,0), 1) # cv2.imshow("resize", image_color) # cv2.waitKey(0) good = sorting.sorting(good) for (i, c) in enumerate(good): draw_contour2(image, c, i) resize = cv2.drawContours(image_color, good, -1, (255, 0, 0), 1) cv2.imshow("resize", image_color) return good # other = cv2.imread("9.png") # ans.answers(other,good) # cv2.waitKey(0) # cv2.destroyAllWindows()
def sortClicked(self): x = sorting(self) x.start()