Example #1
0
 def is_rhombohedral(self) -> bool:
     """Returns true if all lengths are equal and all angles are equal"""
     return (
         self.abc_equal
         and close(np.array(self.angles) - self.angles[0], zeros(3))
         and (not close(self.alpha, np.pi / 2))
     )
Example #2
0
 def angles_different(self) -> bool:
     "are all of the angles alpha, beta, gamma different?"
     return not (
         close(self.alpha, self.beta)
         or close(self.alpha, self.gamma)
         or close(self.beta, self.gamma)
     )
Example #3
0
 def is_hexagonal(self) -> bool:
     """Returns true if lengths a == b, a != c, alpha and beta == 90 and gamma == 120"""
     return (
         close(self.a, self.b)
         and (not close(self.a, self.c))
         and close(self.angles[:2], np.pi / 2)
         and close(self.gamma, 2 * np.pi / 3)
     )
def Frontier_init():
    Frontier = rospy.Publisher('/Frontier', GridCells)
    #find maximum point in empty space in the x and y drection
    Array_EmptyCells = PtArr_Empty
    OCCUPIED = False
    MAX_BOOL = False
    MIN_BOOL = False
    while Array_EmptyCells:
        MAX_Point = max(Array_EmptyCells)
        MIN_Point = min(Array_EmptyCells)
        Frontier_Array = []
        while True:
            #check If the point after the max_point.x is occupied
            for elem in PtArr_Occupied:
                if (numpy.close(MAX_Point.x + RESOLUTION, elem.x) and numpy.close(MAX_Point.y, elem.y)):
                    OCCUPIED = True
                    MAX_BOOL = True
                    break
            for elem in PtArr_Occupied:
                if (numpy.close(MIN_Point.x - RESOLUTION, elem.x) and numpy.close(MIN_Point.y, elem.y)):
                    MIN_BOOL = True
                    OCCUPIED = True
                    break
            if not OCCUPIED:
                if MAX_BOOL:
                    Frontier_Array.append(MAX_Point)    #add it to frontier array
                if MIN_BOOL:
                    Frontier_Array.append(MIN_Point)    #add it to frontier array
        Frontier_MaxPoint = Max_Point
        Frontier_MinPoint = Min_Point
        while True:
            Frontier_MaxPoint.y = Frontier_MaxPoint.y + RESOLUTION    #Next frontier point
            for elem in PtArr_Occupied:
                if numpy.close(Frontier_MaxPoint.y, elem.y ) and numpy.close(MAX_Point.x, elem.x) :
                    Frontier_Array.append(Frontier_MaxPoint)
                    break
            for elem in PtArr_Occupied:
                if numpy.close(Frontier_MinPoint.y, elem.y ) and numpy.close(Frontier_MinPoint.x, elem.x) :
                    Frontier_Array.append(Frontier_MinPoint)
                    break
            break
        #Remove row from frontier array
        for elem in Array_EmptyCells:
            if numpy.close(MAX_Point.y, elem.y):
                Array_EmptyCells.remove(elem)
        
    gridcells_frontier = GridCells()
    gridcells_frontier.header = HEADER
    gridcells_frontier.cell_width = RESOLUTION
    gridcells_frontier.cell_height = RESOLUTION
    gridcells_frontier.cells = Frontier_Array
    Frontier.publish(gridcells_frontier)
    return
Example #5
0
    def is_deterministic(matrix):
        rows, cols = matrix.shape
        answer = True

        for r in range(rows):
            if not np.close(max(matrix[r, :]), sum(matrix[r, :])):
                answer = False
                break
        return answer
Example #6
0
def first_four(thisfolder = ".", newfolder = "first_four"):
    files = os.listdir(thisfolder)
    if not newfolder in files:
        os.mkdir(newfolder)
    for f in files:
        if f[-4:] == ".txt" and f[0] == "r":
            oldpath = os.path.join(thisfolder,f)
            op = open(oldpath,"r")
            newfile = f[:-4] + "FIRSTFOUR.txt"
            newpath = os.path.join(newfolder,newfile)
            np = open(newpath,"w")
            print(f)
            for line in op:
                if re.match(new_referents_line,line):
                    np.close()
                    break
                else:
                    np.write(line)
Example #7
0
    def isInside(self, other: Union['Line', 'Rectangle', 'Circle']) -> bool:
        if isinstance(other, Line):
            AM = Line(other.p1, self)
            MB = Line(self, other.p2)
            return np.close(np.abs(AM.dot(BM)), AM.length * MB.length)

        elif isinstance(other, Rectangle):
            # Based on https://stackoverflow.com/a/2763387
            AB = Line(other.c1, other.c2)
            AM = Line(other.c1, self)
            BC = Line(other.c2, other.c3)
            BM = Line(other.c2, self)

            return 0 <= AB.dot(AM) <= AB.dot(AB) and 0 <= BC.dot(BM) <= BC.dot(
                BC)

        elif isinstance(other, Circle):
            return (self - other.m).norm(p=2) <= other.r

        raise NotImplementedError
Example #8
0
    def serchBtn_event(self):
        hashTag = self.serchWindow.text()
        self.show_heart(self.heart_label, 0)  # 새로 검색을 누르면 하트 초기화
        self.imageList = ['이미지로딩.png']  # 이미지 리스트 초기화
        if os.path.isfile('./contents/' + hashTag + '.tsv') != True:

            # 해시태그 URL
            tagUrl = 'https://www.instagram.com/explore/tags/' + hashTag + '/'

            driver.implicitly_wait(5)

            # 게시글 내용 저장
            cf = open('./contents/' + hashTag + '.txt', 'w', encoding='utf-8')
            df = open('./datetimes/' + hashTag + '.txt', 'w', encoding='utf-8')
            np = open('./postnums/' + hashTag + '.txt', 'w', encoding='utf-8')

            # 웹 사이트 접속
            driver.get(tagUrl)

            post_num = driver.find_element_by_xpath(
                '//*[@id="react-root"]/section/main/header/div[2]/div/div[2]/span/span'
            ).text
            np.write(post_num)
            np.close()

            if not os.path.exists('./photos/' + hashTag):
                os.mkdir('./photos/' + hashTag)

            for j in range(1, 4):  # 이미지 3개 저장
                img_elem = driver.find_element_by_xpath(
                    '//*[@id="react-root"]/section/main/article/div[1]/div/div/div[1]/div['
                    + str(j) + ']/a/div/div[1]/img')
                img_src = img_elem.get_attribute('src')
                img_file_path = './photos/' + hashTag + '/' + hashTag + str(
                    j) + '.jpg'
                urllib.request.urlretrieve(img_src, img_file_path)
                self.imageList.append(img_file_path)

            # 게시글 클릭
            driver.find_element_by_css_selector(
                'div.v1Nh3.kIKUG._bz0w').click()

            for i in range(20):

                time.sleep(2)
                # 게시글에 텍스트가 있으면 읽어들임
                if hasxpath(
                        '/html/body/div[5]/div[2]/div/article/div[3]/div[1]/ul/div/li/div/div/div[2]/span'
                ):
                    post = driver.find_element_by_xpath(
                        '/html/body/div[5]/div[2]/div/article/div[3]/div[1]/ul/div/li/div/div/div[2]/span'
                    ).text
                    post = re.findall('[가-힣]+', post)  # 한국어로 된 게시글만 찾기
                    post = ' '.join(post)
                    check_result = spell_checker.check(post)
                    cor_post = check_result.checked  # 맞춤법 체크
                    if len(cor_post) > 1:
                        cf.write(cor_post + '\n')

                        # 포스팅 시간대 크롤링
                        datetime = driver.find_element_by_tag_name('time')
                        datetime = datetime.get_attribute('datetime')[11:13]
                        df.write(datetime + '\n')

                # 다음 게시글로 넘어가는 화살표 클릭
                driver.find_element_by_css_selector(
                    'a._65Bje.coreSpriteRightPaginationArrow').click()
            cf.close()
            df.close()
        else:
            post_num_path = './postnums/' + hashTag + '.txt'
            f = open(post_num_path, 'r', encoding='utf-8')
            post_num = f.readline()
            f.close()
            for p in range(1, 4):
                img_file_path = 'photos/' + hashTag + '/' + hashTag + str(
                    p) + '.jpg'
                self.imageList.append(img_file_path)

        tsv_path = './contents/' + hashTag + '.tsv'
        txt_path = './contents/' + hashTag + '.txt'
        time_path = './datetimes/' + hashTag + '.txt'
        change_tsv(txt_path, hashTag, 'text')
        test_data = pd.read_csv(tsv_path, encoding='utf-8', sep='\t')
        vocab_path = 'dataset/vocab.txt'

        x_test = read_data(test_data, vocab_path, 50)
        predict = test(model, x_test, 1)
        avg_score = round(avg(predict))  # 평균 점수에서 소수점 버림
        self.show_heart(self.heart_label, avg_score)  # 평점에 따라 이미지 변경
        self.post_num_label.setText(str(post_num))  # 총 게시글 수를 gui 라벨에 나타내기
        self.show_image(self.img1_label, 1)
        self.show_image(self.img2_label, 2)
        self.show_image(self.img3_label, 3)
        make_wordcloud(txt_path, hashTag)
        self.show_wc_or_plt(self.wc_label, hashTag)
        make_timeplt(time_path, hashTag)
        self.show_wc_or_plt(self.plt_label, hashTag)
        self.show()
def open_nparser():
    np = NOMADFieldsParser()
    yield np
    np.close()
Example #10
0
 def is_tetragonal(self) -> bool:
     """Returns true if a, b are equal and all angles are 90 degrees"""
     return close(self.a, self.b) and (not close(self.a, self.c)) and self.orthogonal
Example #11
0
 def is_monoclinic(self) -> bool:
     """Returns true if angles alpha and gamma are equal"""
     return close(self.alpha, self.gamma) and self.abc_different
Example #12
0
 def orthogonal(self) -> bool:
     "returns true if the lattice vectors are orthogonal"
     return close(np.abs(self.angles) - np.pi / 2, zeros(3))
Example #13
0
 def abc_different(self) -> bool:
     "are all of the lengths a, b, c different?"
     return not (
         close(self.a, self.b) or close(self.a, self.c) or close(self.b, self.c)
     )
Example #14
0
 def abc_equal(self) -> bool:
     "are the lengths a, b, c all equal?"
     return close(np.array(self.lengths) - self.lengths[0], zeros(3))
Example #15
0
import cv2
import numpy as np
import imutils

low_red = np.array([50, 150, 30]) #üst ve alt kırmızı değerleri
high_red = np.array([180, 255, 255])

cap= cv2.VideoCapture(0)

kernelOpen=np.ones((5,5)) #morphology alan ayarları
kernelClose=np.close((20,20))
rect= False
try:
    
    while True:
        grabbed, frame= cap.read()
        status= "HEDEF YOK"
        
        if not grabbed:
            continue
        frame=cv2.resize(frame, (340,220))
        hsv=cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
        mask=cv2.inRange(hsv, low_red, high_red)
        res= cv2.bitwise_and(frame, frame, mask=mask)
  
            
        maskOpen=cv2.morphologyEx(mask, cv2.MORPH_OPEN, kernelOpen)
        maskClose=cv2.morphologyEx(maskOpen, cv2.MORPH_CLOSE, kernelClose) #pürüzleri yok et.

        maskSon=maskClose