def test_1():

    #ref https://urllib3.readthedocs.io/en/latest/
    http = urllib3.PoolManager()
    #     r = http.request('GET', 'http://httpbin.org/robots.txt')
    r = http.request('GET', 'http://localhost:8001/ip/dos_attack')

    print()
    print("[%s:%d] r => %s" % \
            (os.path.basename(libs.thisfile()), libs.linenum()
            , r
            ), file=sys.stderr)

    print()
    print("[%s:%d] r.data => %s" % \
            (os.path.basename(libs.thisfile()), libs.linenum()
            , r.data
            ), file=sys.stderr)

    print()
    print("[%s:%d] type(r.data) => %s" % \
            (os.path.basename(libs.thisfile()), libs.linenum()
            , type(r.data)
            ), file=sys.stderr)

    print()
    print("[%s:%d] r.text => %s" % \
            (os.path.basename(libs.thisfile()), libs.linenum()
            , r.text
            ), file=sys.stderr)
def test_2():

    #ref https://qiita.com/Taillook/items/a0f2c59d8e17381fc835
    r = requests.get('http://localhost:8001/ip/dos_attack')

    print()
    print("[%s:%d] r.text => %s" % \
            (os.path.basename(libs.thisfile()), libs.linenum()
            , r.text
            ), file=sys.stderr)

    parser = Parser()
    parser.feed(r.text)

    parser.close()

    print()
    print("[%s:%d] parser => %s" % \
            (os.path.basename(libs.thisfile()), libs.linenum()
            , parser
            ), file=sys.stderr)

    print()
    print("[%s:%d] parser.data => %s" % \
            (os.path.basename(libs.thisfile()), libs.linenum()
            , parser.data
            ), file=sys.stderr)

    for i in parser.data:
        print("Title: " + i["title"], "\nLink: " + i["link"] + "\n")
def get_Scaling(args):

    # scaling
    scaling = 1.0

    #     #debug
    #     print("[%s:%d] args =>" % \
    #                 (os.path.basename(libs.thisfile()), libs.linenum()
    #
    #                 ), file=sys.stderr)
    #     print(args)

    if len(args) > 0:  #if len(args) > 1

        optlist, args = getopt.getopt(args, "s:")

        print("[%s:%d] optlist =>" % \
            (os.path.basename(libs.thisfile()), libs.linenum()

            ), file=sys.stderr)
        print(optlist)

        for item in optlist:

            #debug
            print("[%s:%d] item =>" % \
            (os.path.basename(libs.thisfile()), libs.linenum()

            ), file=sys.stderr)
            print(item)

            if item[0].startswith("-s"):  #if item.startswith("-s")

                scaling = float(item[1])

                break

            #/if item.startswith("-s")

        #/for item in optlist:

    else:  #if len(args) > 1

        print("[%s:%d] len(args) < 2" % \
            (os.path.basename(libs.thisfile()), libs.linenum()

            ), file=sys.stderr)

    #/if len(args) > 1

    #debug
    print("[%s:%d] scaling => %.3f" % \
            (os.path.basename(libs.thisfile()), libs.linenum()
            , scaling
            ), file=sys.stderr)
    '''###################
        return        
    ###################'''
    return scaling
def __key_Inputs__EXECUTE__V2__Save_SubImage(key_inputs, img_ForDisp,
                                             time_Label):
    '''###################
        validate
    ###################'''
    if refPt_Start == [-1, -1] or refPt_End == [
            -1, -1
    ]:  #if refPt_Start == [-1,-1] or refPt_End == [-1,-1]

        print("[%s:%d] start/end points ==> not yet set" % \
            (os.path.basename(libs.thisfile()), libs.linenum()

            ), file=sys.stderr)

        return

    #/if refPt_Start == [-1,-1] or refPt_End == [-1,-1]
    '''###################
        sub image        
    ###################'''

    img_Sub = img_ForDisp[
        #                 refPt_Start[0] : refPt_End[0]     # x axis
        #                 , refPt_Start[1] : refPt_End[1]       # y axis
        refPt_Start[1]:refPt_End[1]  # y axis
        , refPt_Start[0]:refPt_End[0]  # x axis
        #                 , refPt_Start[0] : refPt_Start[0] + 10
        #                 refPt_Start[0] : refPt_Start[0] + 10
        #                 , refPt_Start[1] : refPt_End[1]
    ]

    # file name
    #             % (libs.get_TimeLabel_Now()
    fname = "subimage_%s.%d-%d_%d-%d.png" \
            % (time_Label
               , refPt_Start[1], refPt_End[1]
               , refPt_Start[0], refPt_End[0])

    fpath_Save_Image = os.path.join(DPATH_IMAGE_OUTPUT, fname)

    #ref save image https://docs.opencv.org/3.0-beta/doc/py_tutorials/py_gui/py_image_display/py_image_display.html
    result = cv2.imwrite(fpath_Save_Image, img_Sub)

    print("[%s:%d] saving image ==> %s (%s)" % \
                (os.path.basename(libs.thisfile()), libs.linenum()
                , result, fpath_Save_Image
                ), file=sys.stderr)
    '''###################
        return        
    ###################'''
    return img_Sub
def __test_2__Color_Filtering_HSV__Save_Image(args, img_Orig):
    '''###################
        prep
    ###################'''
    img_BGR = cv2.cvtColor(img_Orig, cv2.COLOR_RGB2BGR)
    img_HSV = cv2.cvtColor(img_Orig, cv2.COLOR_RGB2HSV)

    img_ForDisp = img_HSV
    #     img_ForDisp = img_BGR
    #     img_ForDisp = img_Orig
    '''###################
        save image        
    ###################'''
    # file name
    file_label = "image_HSV"
    #     file_label = "image_BGR"
    #     file_label = "image_RGB"

    fname = "%s.%s.png" % (file_label, libs.get_TimeLabel_Now())

    fpath_Save_Image = os.path.join(DPATH_IMAGE_OUTPUT, fname)

    #ref save image https://docs.opencv.org/3.0-beta/doc/py_tutorials/py_gui/py_image_display/py_image_display.html
    result = cv2.imwrite(fpath_Save_Image, img_ForDisp)

    print("[%s:%d] saving image ==> %s (%s)" % \
                (os.path.basename(libs.thisfile()), libs.linenum()
                , result, fpath_Save_Image
                ), file=sys.stderr)
def __key_Inputs(key_inputs, img_ForDisp):
    '''######################################
        dispatch        
    ###################'''
    '''###################
        key : x        
    ###################'''
    if key_inputs == KEY_INPUTS__EXECUTE:  #if key

        __key_Inputs__EXECUTE(key_inputs, img_ForDisp)

#         print("[%s:%d] key_inputs => '%s'" % \
#             (os.path.basename(libs.thisfile()), libs.linenum()
#             , key_inputs
#             ), file=sys.stderr)
#         print("refPt_Start =>")
#         print(refPt_Start)
#         print("refPt_End =>")
#         print(refPt_End)

    else:  #if key

        print("[%s:%d] unknown key ==> '%s'" % \
            (os.path.basename(libs.thisfile()), libs.linenum()
            , key_inputs
            ), file=sys.stderr)
def click_and_crop(event, x, y, flags, param):

    print()
    print("[%s:%d] x = %d, y = %d" % \
            (os.path.basename(libs.thisfile()), libs.linenum()
            , x, y
            ), file=sys.stderr)
def __test_1__Set_Starting_Point__Plotting(lo_Rs, lo_Gs, lo_Bs,
                                           dpath_Ops_Images):

    y_pos = np.arange(len(lo_Rs))

    performance = lo_Rs

    #ref https://stackoverflow.com/questions/21254472/multiple-plot-in-one-figure-in-python
    plt.plot(y_pos, lo_Rs, 'r-', label='lo_Rs')
    plt.plot(y_pos, lo_Gs, 'g-', label='lo_Gs')
    plt.plot(y_pos, lo_Bs, 'b-', label='lo_Bs')

    plt.legend(loc='best')

    ax = plt.gca()

    #ref grid https://stackoverflow.com/questions/16074392/getting-vertical-gridlines-to-appear-in-line-plot-in-matplotlib
    ax.grid(which='major', axis='both', linestyle='--')
    ax.grid(which='minor', axis='both', linestyle='--')

    ax.set(aspect=1, xlim=(0, len(lo_Rs)), ylim=(0, 260))
    #            ylim=(140, 250))

    fpath_Save_Image = os.path.join(
        dpath_Ops_Images, "plot_" + libs.get_TimeLabel_Now() + ".png")

    result = plt.savefig(fpath_Save_Image)

    #     print("[%s:%d] save fig => %s (%s)" % \
    print("[%s:%d] save fig (graph) => %s (%s)" % \
        (os.path.basename(libs.thisfile()), libs.linenum()
        , result, fpath_Save_Image
        ), file=sys.stderr)
def test_1():
    '''######################################
        ops        
    ######################################'''
    dpath_Ops_Images = "C:\\WORKS_2\\WS\\WS_Others.Art\\JVEMV6\\46_art\\VIRTUAL\\Admin_Projects\\ip\\data\\ops\\images"
    fname_Ops_Image = "2018-06-24_19-14-31_000.jpg"

    fpath_Ops_Image = os.path.join(dpath_Ops_Images, fname_Ops_Image)
    '''###################
        get : image
    ###################'''
    # read image
    img_Orig = cv2.imread(fpath_Ops_Image)

    img_Orig_RGB = cv2.cvtColor(img_Orig, cv2.COLOR_BGR2RGB)

    # meta data
    height, width, channels = img_Orig.shape
    '''######################################
        show : image
    ######################################'''
    window_1 = "window"

    #ref https://qiita.com/supersaiakujin/items/54a4671142d80ca962ec
    cv2.namedWindow(window_1)
    #     cv2.namedWindow('window')
    '''###################
        mouse events
    ###################'''
    #ref https://www.pyimagesearch.com/2015/03/09/capturing-mouse-click-events-with-python-and-opencv/
    cv2.setMouseCallback(window_1, click_and_crop)
    #     cv2.setMouseCallback("image", click_and_crop)
    '''###################
        show
    ###################'''
    #     while True :
    #
    #         cv2.imshow(window_1, img_Orig_RGB)
    # #         cv2.imshow('window', img_Orig_RGB)
    #     #     cv2.imshow('window', img_Orig)
    #     #     cv2.imshow('window', I)
    #
    #         cv2.waitKey(0)
    #         cv2.destroyAllWindows()

    cv2.imshow('window', img_Orig_RGB)
    #     cv2.imshow('window', img_Orig)
    #     cv2.imshow('window', I)

    cv2.waitKey(0)
    cv2.destroyAllWindows()
    '''###################
        message
    ###################'''
    print()
    print("[%s:%d] test_1 =======================" % \
                    (os.path.basename(libs.thisfile()), libs.linenum()

                    ), file=sys.stderr)
示例#10
0
def open_dir(request):
    '''###################
        params
    ###################'''
    param = request.GET.get('param', False)

    print("[%s:%d] param => %s" % \
        (os.path.basename(libs.thisfile()), libs.linenum()
        , param
        ), file=sys.stderr)
    '''###################
        vars        
    ###################'''
    dic = {}

    print()
    print("[%s:%d] opening dir..." % \
            (os.path.basename(libs.thisfile()), libs.linenum()

            ), file=sys.stderr)
    '''###################
        build : command string        
    ###################'''
    command = "C:\\WORKS_2\\WS\\WS_Others.Art\\JVEMV6\\46_art\\VIRTUAL\\Admin_Projects\\anims\\utils\\open_anims_log_dir.bat"
    #     command = "C:\\WORKS_2\\WS\\WS_Others.Art\\JVEMV6\\46_art\\VIRTUAL\\Admin_Projects\\ip\\utils\\open_anims_log_dir.bat"

    cmd_Full = [command]  #=>

    print()
    print("[%s:%d] command => %s" % \
            (os.path.basename(libs.thisfile()), libs.linenum()
            , command
            ), file=sys.stderr)
    '''###################
        subprocess        
    ###################'''
    #ref https://stackoverflow.com/questions/13525882/tasklist-output answered Nov 23 '12 at 9:36
    res = subprocess.call(cmd_Full)
    #     res = subprocess.check_output(cmd_Full)
    '''###################
        render
    ###################'''
    return render(request, 'anims/anims/plain_anims.html', dic)
示例#11
0
def exec_prog():
    '''###################
        ops        
    ###################'''
    #     test_2()
    test_1()

    print("[%s:%d] exec_prog() => done" % \
            (os.path.basename(libs.thisfile()), libs.linenum()

            ), file=sys.stderr)
def exec_prog():
    '''###################
        ops        
    ###################'''
    test_2__Color_Filtering_HSV()
    #     test_1__Color_Filtering()

    print("[%s:%d] exec_prog() => done" % \
            (os.path.basename(libs.thisfile()), libs.linenum()

            ), file=sys.stderr)
def exec_prog():  # from :

    test_4__Thread__V2()
    #     test_4__Thread()
    #     test_3()
    #     test_2()
    #     test_1()
    '''###################
        Report        
    ###################'''
    print("[%s:%d] exec_prog => done" %
          (os.path.basename(libs.thisfile()), libs.linenum()))
def exec_prog():
    '''###################
        ops        
    ###################'''
    #     test_8__Matplotlib__Bar_Chart()

    test_1__Set_Starting_Point()

    print("[%s:%d] exec_prog() => done" % \
            (os.path.basename(libs.thisfile()), libs.linenum()

            ), file=sys.stderr)
def __key_Inputs__RGB(img_ForDisp):

    global flg_Get_RGB_Vals

    if flg_Get_RGB_Vals == True:  #if flg_Get_RGB_Vals == True

        flg_Get_RGB_Vals = False

        print("[%s:%d] flg_Get_RGB_Vals ==> now : %s" % \
        (os.path.basename(libs.thisfile()), libs.linenum()
        , flg_Get_RGB_Vals
        ), file=sys.stderr)

    else:  #if flg_Get_RGB_Vals == True

        flg_Get_RGB_Vals = True

        print("[%s:%d] flg_Get_RGB_Vals ==> now : %s" % \
        (os.path.basename(libs.thisfile()), libs.linenum()
        , flg_Get_RGB_Vals
        ), file=sys.stderr)
def get_GPS_Data(fpath_Image):
    
    dicOf_Exif = get_exif_of_image(fpath_Image)# def get_GPS_Data():
    
    gps_Info = dicOf_Exif['GPSInfo']
    
    '''###################
        lat, longi        
    ###################'''
    txt_Lat = "%s=" % (gps_Info[1])
    txt_Longi = "%s=" % (gps_Info[3])

    '''###################
        values
    ###################'''
    vals_Lat = gps_Info[2]
    
    txt_Lat += "%d-%d-%.02f" % \
            (vals_Lat[0][0], vals_Lat[1][0], vals_Lat[2][0] * 1.0 / vals_Lat[2][1])
#             (vals_Lat[0][0], vals_Lat[1][0])

    vals_Longi = gps_Info[4]
    
    txt_Longi += "%d-%d-%.02f" % \
            (vals_Longi[0][0], vals_Longi[1][0], vals_Longi[2][0] * 1.0 / vals_Longi[2][1])

#     txt_Longi += "%d-%d-" % \
#             (vals_Longi[0][0], vals_Longi[1][0])

    
    '''###################
        tuples
    ###################'''
    data_Lat = (gps_Info[1], vals_Lat[0][0], vals_Lat[1][0], vals_Lat[2][0] * 1.0 / vals_Lat[2][1])
    data_Longi = (gps_Info[3], vals_Longi[0][0], vals_Longi[1][0], vals_Longi[2][0] * 1.0 / vals_Longi[2][1])
    
    data_Final = (data_Lat, data_Longi)
    
    '''###################
        report        
    ###################'''
    print("[%s:%d] txt_Lat = %s, txt_Longi = %s" % \
            (os.path.basename(libs.thisfile()), libs.linenum()
            , txt_Lat, txt_Longi
            ), file=sys.stderr)
    
    '''###################
        return        
    ###################'''
    return data_Final
def __key_Inputs__EXECUTE(key_inputs, img_ForDisp):

    print("[%s:%d] key_inputs => '%s'" % \
        (os.path.basename(libs.thisfile()), libs.linenum()
        , key_inputs
        ), file=sys.stderr)
    #     print("refPt_Start =>")
    #     print(refPt_Start)
    #     print("refPt_End =>")
    #     print(refPt_End)
    '''###################
        ops : V2        
    ###################'''
    __key_Inputs__EXECUTE__V2(key_inputs, img_ForDisp)
    '''###################
def test_3():

    #ref https://qiita.com/Taillook/items/a0f2c59d8e17381fc835
    r = requests.get('http://localhost:8001/ip/dos_attack')

    #ref https://qiita.com/itkr/items/513318a9b5b92bd56185
    #ref r.text https://stackoverflow.com/questions/36709165/beautifulsoup-object-of-type-response-has-no-len#36709275 answered Apr 19 '16 at 5:25
    soup = BS(r.text)
    #     soup = BS(r)

    print()
    print("[%s:%d] soup => %s" % \
            (os.path.basename(libs.thisfile()), libs.linenum()
            , soup
            ), file=sys.stderr)
def __key_Inputs__EXECUTE__Gen_RGBGraph(img_Target):
    '''###################
        get : values        
    ###################'''
    lo_Rs, lo_Gs, lo_Bs = get_RGB_Vals(img_Target)

    print()
    print("[%s:%d] len(lo_Rs) => %d" % \
                (os.path.basename(libs.thisfile()), libs.linenum()
                , len(lo_Rs)
                ), file=sys.stderr)
    '''###################
        plot        
    ###################'''
    dpath_Ops_Images = DPATH_IMAGE_OUTPUT

    __test_1__Set_Starting_Point__Plotting(lo_Rs, lo_Gs, lo_Bs,
                                           dpath_Ops_Images)
def __key_Inputs__EXECUTE__V2(key_inputs, img_ForDisp):

    print("[%s:%d] __key_Inputs__EXECUTE__V2" % \
        (os.path.basename(libs.thisfile()), libs.linenum()

        ), file=sys.stderr)
    '''###################
        save : sub image
    ###################'''
    time_Label = libs.get_TimeLabel_Now()

    img_Sub = __key_Inputs__EXECUTE__V2__Save_SubImage(key_inputs, img_ForDisp,
                                                       time_Label)
    #     img_Sub = __key_Inputs__EXECUTE__V2__Save_SubImage(key_inputs, img_ForDisp)
    '''###################
        graph
    ###################'''
    __key_Inputs__EXECUTE__V2__RGB_Graph(key_inputs, img_Sub, time_Label)
def exec_prog():
    '''###################
        ops        
    ###################'''
    #     test_8__Matplotlib__Bar_Chart()
    test_7__SubImage_RGB_Vals()
    #     test_6__Get_SubImage()
    #     test_5()
    #     test_4()
    #     test_2()
    #     test_3()
    #     test_2()
    #     test_1()

    print("[%s:%d] exec_prog() => done" % \
            (os.path.basename(libs.thisfile()), libs.linenum()

            ), file=sys.stderr)
def __key_Inputs__EXECUTE__V2__Plot_RGB(lo_Rs, lo_Gs, lo_Bs, fpath_Image):

    y_pos = np.arange(len(lo_Rs))

    performance = lo_Rs
    '''###################
        reset : plot        
    ###################'''
    #ref https://stackoverflow.com/questions/8213522/when-to-use-cla-clf-or-close-for-clearing-a-plot-in-matplotlib#8228808
    plt.clf()

    #ref https://stackoverflow.com/questions/21254472/multiple-plot-in-one-figure-in-python
    #     plt.plot(lo_Rs, 'r-', label='lo_Rs')
    #     plt.plot(lo_Rs, 'r+', label='lo_Rs')
    plt.plot(y_pos, lo_Rs, 'r-', label='lo_Rs')
    plt.plot(y_pos, lo_Gs, 'g-', label='lo_Gs')
    plt.plot(y_pos, lo_Bs, 'b-', label='lo_Bs')

    plt.legend(loc='best')

    ax = plt.gca()

    #ref grid https://stackoverflow.com/questions/16074392/getting-vertical-gridlines-to-appear-in-line-plot-in-matplotlib
    ax.grid(which='major', axis='both', linestyle='--')
    ax.grid(which='minor', axis='both', linestyle='--')

    ax.set(aspect=1, xlim=(0, len(lo_Rs)), ylim=(0, 260))
    #            ylim=(140, 250))

    fpath_Save_Image = fpath_Image
    #     fpath_Save_Image = os.path.join(dpath_Ops_Images, "plot_" + libs.get_TimeLabel_Now() + ".png")

    result = plt.savefig(fpath_Save_Image)

    plt.show()

    #     print("[%s:%d] save fig => %s (%s)" % \
    print("[%s:%d] save fig (graph) => %s (%s)" % \
        (os.path.basename(libs.thisfile()), libs.linenum()
        , result, fpath_Save_Image
        ), file=sys.stderr)
def worker():
    """thread worker function"""

    r = requests.get('http://localhost:8001/ip/dos_attack/')
    #     r = requests.get('http://localhost:8001/ip/dos_attack')

    #ref https://qiita.com/itkr/items/513318a9b5b92bd56185
    #ref r.text https://stackoverflow.com/questions/36709165/beautifulsoup-object-of-type-response-has-no-len#36709275 answered Apr 19 '16 at 5:25
    soup = BS(r.text, "html.parser")
    #     soup = BS(r.text)

    print()
    print("[%s:%d] soup => done" % \
            (os.path.basename(libs.thisfile()), libs.linenum()

            ), file=sys.stderr)
    #     soup = BS(r)

    #     print ('Worker')

    return
示例#24
0
def _anims__Load_LO_Actions():

    dpath_List = "C:\\WORKS_2\\WS\\WS_Others.Art\\JVEMV6\\46_art\\VIRTUAL\\Admin_Projects\\ip\\data"

    fname_List = "anims_listof_commands.dat"

    fpath_List = os.path.join(dpath_List, fname_List)

    f = open(fpath_List, "r")

    # header line
    f.readline()

    # body lines
    lines = f.readlines()

    # close file
    f.close()

    lo_Commands = []

    # build list
    for item in lines:

        lo_Commands.append(item.split("\t")[1:])

    #/for item in lines:

    #debug
    print()
    print("[%s:%d] lo_Commands =>" % \
        (os.path.basename(libs.thisfile()), libs.linenum()

        ), file=sys.stderr)
    print(lo_Commands)

    return lo_Commands
示例#25
0
def test_1():
    '''###################
        list : file names in the dir        
    ###################'''
    dpath = "C:\\WORKS_2\\WS\\WS_Others.Art\\JVEMV6\\46_art\\11_guitar\\sounds\\mp3"

    fpath_Glob = "%s\\*.mp3" % (dpath)

    #ref glob https://stackoverflow.com/questions/14798220/how-can-i-search-sub-folders-using-glob-glob-module-in-python answered Feb 10 '13 at 13:31
    lo_Files = glob.glob(fpath_Glob)

    lo_Files = [os.path.basename(x) for x in lo_Files]

    #ref https://stackoverflow.com/questions/678236/how-to-get-the-filename-without-the-extension-from-a-path-in-python answered Mar 24 '09 at 16:43
    lo_Files_Trunk = [
        os.path.splitext(os.path.basename(x))[0] for x in lo_Files
    ]
    #     lo_Files_Trunk = [os.path.splitext(x)[0] for x in lo_Files]

    lo_Name_Sets = list(zip(lo_Files, lo_Files_Trunk))

    # report
    print()
    print("[%s:%d] lo_Name_Sets =>" % \
            (os.path.basename(libs.thisfile()), libs.linenum()

            ), file=sys.stderr)
    for item in lo_Name_Sets:

        print(item)

    #/for item in lo_Name_Sets:
    '''###################
        list : file names in the text file        
    ###################'''
    fname_ListFile = "list-of-new-file-names.txt"

    fpath_ListFile = "%s\\%s" % (dpath, fname_ListFile)

    #     #debug
    #     print()
    #     print("[%s:%d] fpath_ListFile => %s" % \
    #             (os.path.basename(libs.thisfile()), libs.linenum()
    #             , fpath_ListFile
    #             ), file=sys.stderr)
    #     return

    fin = open(fpath_ListFile, "r")

    lo_FileName_Final = []

    lo_file_Lines = []

    lo_file_Lines = fin.readlines()

    #ref strip https://hydrocul.github.io/wiki/programming_languages_diff/string/trim.html
    lo_file_Lines = [x.strip() for x in lo_file_Lines]

    print()
    print("[%s:%d] lo_file_Lines =>" % \
            (os.path.basename(libs.thisfile()), libs.linenum()

            ), file=sys.stderr)
    print(lo_file_Lines)

    lo_file_Lines_Trunk = [x.split(".") for x in lo_file_Lines]

    print()
    print("[%s:%d] lo_file_Lines_Trunk =>" % \
            (os.path.basename(libs.thisfile()), libs.linenum()

            ), file=sys.stderr)
    print(lo_file_Lines_Trunk)

    #     return

    lo_file_Lines_Trunk = [x[0] for x in lo_file_Lines_Trunk]

    print()
    print("[%s:%d] lo_file_Lines_Trunk ('x[0] for x in ...') =>" % \
            (os.path.basename(libs.thisfile()), libs.linenum()

            ), file=sys.stderr)
    print(lo_file_Lines_Trunk)

    lo_file_Lines_Trunk = [x.split(" ") for x in lo_file_Lines_Trunk]
    #     lo_file_Lines_Trunk = [x.split("_") for x in lo_file_Lines_Trunk]
    lo_file_Lines_Trunk = [x[0] + "_" + x[1] for x in lo_file_Lines_Trunk]
    #     lo_file_Lines_Trunk = [x[0] + " " + x[1] for x in lo_file_Lines_Trunk]
    #     lo_file_Lines_Trunk = [(x[0], x[1]) for x in lo_file_Lines_Trunk]

    print()
    print("[%s:%d] lo_file_Lines_Trunk (modified) =>" % \
            (os.path.basename(libs.thisfile()), libs.linenum()

            ), file=sys.stderr)
    print(lo_file_Lines_Trunk)

    # zip
    lo_file_Lines = list(zip(lo_file_Lines, lo_file_Lines_Trunk))

    print()
    print("[%s:%d] lo_file_Lines =>" % \
            (os.path.basename(libs.thisfile()), libs.linenum()

            ), file=sys.stderr)

    for item in lo_file_Lines:

        print(item)

    #/for item in lo_file_Lines:
    '''###################
        judge        
    ###################'''
    lenOf_Name_Sets = len(lo_Name_Sets)

    cntOf_Changed_Files = 0

    # file
    fpath_Log = os.path.join(dpath, "ops.log")

    f_log = open(fpath_Log, "a")

    f_log.write("[%s / %s:%d]=======================" % \
                (libs.get_TimeLabel_Now()
                 , os.path.basename(libs.thisfile())
                 , libs.linenum()))

    f_log.write("\n")

    for i in range(lenOf_Name_Sets):

        name_Set = lo_Name_Sets[i]

        for item in lo_file_Lines:

            # judge
            if name_Set[1] == item[1]:  #if name_Set[1] == item[1]

                msg = "[%s / %s:%d] change file name => name_Set[1] = %s, item[1] = %s" % \
                    (libs.get_TimeLabel_Now()
                    , os.path.basename(libs.thisfile())
                    , libs.linenum()
                    , name_Set[1], item[1]
                    )

                print()
                print(msg, file=sys.stderr)
                #                 print("[%s:%d] change file name => name_Set[1] = %s, item[1] = %s" % \
                #                     (os.path.basename(libs.thisfile()), libs.linenum()
                #                     , name_Set[1], item[1]
                #                     ), file=sys.stderr)

                f_log.write(msg)
                f_log.write("\n")

                msg = "from : %s / to : %s" % (name_Set[0], item[0])
                print(msg)
                #                 print("from : %s / to : %s" % (name_Set[0], item[0]))

                f_log.write(msg)
                f_log.write("\n")

                # rename
                fpath_Curr = os.path.join(dpath, name_Set[0])
                fpath_New = os.path.join(dpath, item[0])

                #ref rename https://qiita.com/clarinet758/items/307d01a6634b372e8fa9
                os.rename(fpath_Curr, fpath_New)

                # count
                cntOf_Changed_Files += 1

                break

            #/if name_Set[1] == item[1]

        #/for item in lo_file_Lines:

    #/for i in range(lenOf_Name_Sets):

    # write count
    f_log.write("renamed : %d files" % cntOf_Changed_Files)

    f_log.write("\n")

    f_log.write("\n")  # <= spacer line

    # close log file
    f_log.close()
    '''###################
        report        
    ###################'''
    print()
    print("[%s:%d] cntOf_Changed_Files => %d" % \
                    (os.path.basename(libs.thisfile()), libs.linenum()
                    , cntOf_Changed_Files
                    ), file=sys.stderr)
示例#26
0
# #                 (get_TimeLabel_Now(), fs, f0, "%1.2f" % (phase_Param / 4.0) + "pi", sec)
# #     fname_Out = "audio/output_%s.sin.fs-%d_f0-%d_phase-%d_sec-%d.wav" % \
# #                 (get_TimeLabel_Now(), fs, f0, phase, sec)
#
#     save_Wave(fname_Out, wave_Params, binwave)
#def exec_prog()
'''
<usage>
test_1.py [-fXXX]  #=> frequency
test_1.py -f402
'''
if __name__ == "__main__":
    '''###################
    	validate : help option		
    ###################'''
    '''###################
    	get options		
    ###################'''
    '''###################
    	evecute		
    ###################'''
    exec_prog()

    print()

    print("[%s:%d] done" % \
            (os.path.basename(libs.thisfile()), libs.linenum()

            ), file=sys.stderr)
#     print "[%s:%d] done" % (thisfile(), linenum())
示例#27
0
def test_1():
    
    #debug
    print("[%s:%d] test_1() --> stareting..." % \
            (os.path.basename(libs.thisfile()), libs.linenum()
            
            ), file=sys.stderr)
    
    '''######################################
        prep
    ######################################'''
    dpath_Ops_Videos = "C:\\WORKS_2\\WS\\WS_Others.Art\\JVEMV6\\46_art\\VIRTUAL\\Admin_Projects\\ip\\data\\ops\\3_opencv\\1_motion-detection\\data"
#     C:\WORKS_2\WS\WS_Others.Art\JVEMV6\46_art\VIRTUAL\Admin_Projects\ip\data\ops\3_opencv\1_motion-detection\data
    fname_Ops_Video = "2018-08-24_06-20-53_000.mov.0-10-sec.avi"
#     fname_Ops_Video = "vtest.avi"
     
    fpath_Ops_Video = os.path.join(dpath_Ops_Videos, fname_Ops_Video)

    '''###################
        ops
    ###################'''
    # 定数定義
    ESC_KEY = 27     # Escキー
    INTERVAL= 33     # インターバル
    FRAME_RATE = 30  # fps
    
    WINDOW_ORG = "org"
    WINDOW_BACK = "back"
    WINDOW_DIFF = "diff"
    
    FILE_ORG = fpath_Ops_Video
#     FILE_ORG = "org_768x576.avi"
    
    # ウィンドウの準備
    cv2.namedWindow(WINDOW_ORG)
    cv2.namedWindow(WINDOW_BACK)
    cv2.namedWindow(WINDOW_DIFF)
    
    # 元ビデオファイル読み込み
    mov_org = cv2.VideoCapture(FILE_ORG)
    
    # 最初のフレーム読み込み
    has_next, i_frame = mov_org.read()
    
    # 背景フレーム
    back_frame = np.zeros_like(i_frame, np.float32)

    #debug
    print("[%s:%d] prep done. starting while loop..." % \
            (os.path.basename(libs.thisfile()), libs.linenum()
            
            ), file=sys.stderr)

    
    # 変換処理ループ
    while has_next == True:
        # 入力画像を浮動小数点型に変換
        f_frame = i_frame.astype(np.float32)
    
        # 差分計算
        diff_frame = cv2.absdiff(f_frame, back_frame)
    
        # 背景の更新
        cv2.accumulateWeighted(f_frame, back_frame, 0.025)
    
        # フレーム表示
        cv2.imshow(WINDOW_ORG, i_frame)
        cv2.imshow(WINDOW_BACK, back_frame.astype(np.uint8))
        cv2.imshow(WINDOW_DIFF, diff_frame.astype(np.uint8))
    
        # Escキーで終了
        key = cv2.waitKey(INTERVAL)
        if key == ESC_KEY:
            break
    
        # 次のフレーム読み込み
        has_next, i_frame = mov_org.read()

    #debug
    print("[%s:%d] while loop done..." % \
            (os.path.basename(libs.thisfile()), libs.linenum()
            
            ), file=sys.stderr)
    
    # 終了処理
    cv2.destroyAllWindows()
    mov_org.release()    
    
    '''###################
        message
    ###################'''
    print()
#     print("[%s:%d] test_1 =======================" % \
    print("[%s:%d] test_1 ======================= done" % \
                    (os.path.basename(libs.thisfile()), libs.linenum()

                    ), file=sys.stderr)
def test_5__Resize_Image(width, height, scaling, scr_W, scr_H):

    q1 = 1.0 * width / height

    s = scaling

    flg_WorH = ""

    # j1
    if s >= 0:  #if s >= 0

        ### j1 : p1
        A = 0

        if width >= height:  #if width > height

            flg_WorH = "width"

            A = width

        else:  #if width > height

            flg_WorH = "height"

            A = height

        #/if width > height

        ### j1 : p2
        m = A * s

        print("[%s:%d] m => %.03f" % \
                (os.path.basename(libs.thisfile()), libs.linenum()
                , m
                ), file=sys.stderr)

        ### j1 : p3
        Z = 0

        if flg_WorH == "width":  #if flg_WorH == "width"

            Z = scr_W

        else:  #if flg_WorH == "width"

            Z = scr_H

        #/if flg_WorH == "width"

        ### j2
        result = (m > Z)
        '''###################
            vars
        ###################'''
        win_Resize_Height = 0
        win_Resize_Width = 0

        if result == True:  #if result == True

            print("[%s:%d] m > Z : m = %.03f, Z = %d, flg_WorH = %s" % \
                (os.path.basename(libs.thisfile()), libs.linenum()
                , m, Z, flg_WorH
                ), file=sys.stderr)

            ### j2 : p1
            q2 = 1.0 * Z / A

            print("[%s:%d] q2 => %.03f" % \
                    (os.path.basename(libs.thisfile()), libs.linenum()
                    , q2
                    ), file=sys.stderr)
            '''###################
                calc
            ###################'''
            win_Resize_Height = math.floor(height * q2)
            win_Resize_Width = math.floor(width * q2)
#             win_Resize_Height = int(height * q2)
#             win_Resize_Width = int(width * q2)
#             win_Resize_Height = height * q2
#             win_Resize_Width = width * q2

        else:  #if result == True

            print("[%s:%d] m <= Z" % \
                    (os.path.basename(libs.thisfile()), libs.linenum()

                    ), file=sys.stderr)
            '''###################
                calc
            ###################'''
            win_Resize_Height = math.floor(scaling * height)
            win_Resize_Width = math.floor(scaling * width)

        #/if result == True

    else:  #if s >= 0
        '''###################
            calc
        ###################'''
        win_Resize_Height = math.floor(scaling * height)
        win_Resize_Width = math.floor(scaling * width)

    #/if s >= 0

#     '''###################
#         calc
#     ###################'''
#     win_Resize_Height = math.floor(scaling * height)
#     win_Resize_Width = math.floor(scaling * width)
    '''###################
        return        
    ###################'''
    #debug
    print("[%s:%d] win_Resize_Width = %d, win_Resize_Height = %d" % \
            (os.path.basename(libs.thisfile()), libs.linenum()
            , win_Resize_Width, win_Resize_Height
            ), file=sys.stderr)
    print()

    return win_Resize_Width, win_Resize_Height
def test_4():
    '''###################
        message
    ###################'''
    print()
    print("[%s:%d] test_4 =======================" % \
        (os.path.basename(libs.thisfile()), libs.linenum()

        ), file=sys.stderr)
    '''######################################
        get : args
    ##################
    ####################'''
    args = sys.argv[1:]
    #     args = sys.argv
    '''######################################
        ops        
    ######################################'''
    dpath_Ops_Images = "C:\\WORKS_2\\WS\\WS_Others.Art\\JVEMV6\\46_art\\VIRTUAL\\Admin_Projects\\ip\\data\\ops\\images"
    #     "C:\WORKS_2\WS\WS_Others.Art\JVEMV6\46_art\VIRTUAL\Admin_Projects\ip\data\ops\images"

    fname_Ops_Image = "2018-06-24_19-14-31_000.jpg"

    fpath_Ops_Image = os.path.join(dpath_Ops_Images, fname_Ops_Image)
    '''###################
        get : image
    ###################'''
    # read image
    img_Orig = cv2.imread(fpath_Ops_Image)

    img_Orig_RGB = cv2.cvtColor(img_Orig, cv2.COLOR_BGR2RGB)

    img_ForDisp = img_Orig

    # meta data
    height, width, channels = img_ForDisp.shape
    #     height, width, channels = img_Orig.shape
    '''######################################
        prep : window
    ######################################'''
    window_1 = "window"

    #ref https://qiita.com/supersaiakujin/items/54a4671142d80ca962ec
    #ref resize window http://answers.opencv.org/question/84985/resizing-the-output-window-of-imshow-function/
    cv2.namedWindow(window_1, cv2.WINDOW_NORMAL)

    # scaling
    scaling = 1.0

    #debug
    print("[%s:%d] args =>" % \
                (os.path.basename(libs.thisfile()), libs.linenum()

                ), file=sys.stderr)
    print(args)

    if len(args) > 0:  #if len(args) > 1
        #     if len(args) > 1 : #if len(args) > 1

        optlist, args = getopt.getopt(args, "s:")

        print("[%s:%d] optlist =>" % \
            (os.path.basename(libs.thisfile()), libs.linenum()

            ), file=sys.stderr)
        print(optlist)

        for item in optlist:

            #debug
            print("[%s:%d] item =>" % \
            (os.path.basename(libs.thisfile()), libs.linenum()

            ), file=sys.stderr)
            print(item)

            if item[0].startswith("-s"):  #if item.startswith("-s")

                scaling = float(item[1])
                #                 scaling = item[1]

                break

            #/if item.startswith("-s")

        #/for item in optlist:

    else:  #if len(args) > 1

        print("[%s:%d] len(args) < 2" % \
            (os.path.basename(libs.thisfile()), libs.linenum()

            ), file=sys.stderr)

    #/if len(args) > 1

#     scaling = 0.5

#debug
    print("[%s:%d] scaling => %.3f" % \
            (os.path.basename(libs.thisfile()), libs.linenum()
            , scaling
            ), file=sys.stderr)

    win_Resize_Height = math.floor(scaling * height)
    win_Resize_Width = math.floor(scaling * width)

    # validate
    scr_W = GetSystemMetrics(0)
    scr_H = GetSystemMetrics(1)

    if win_Resize_Width > scr_W: win_Resize_Width = scr_W
    if win_Resize_Height > scr_H: win_Resize_Width = scr_H

    #debug
    print("[%s:%d] win_Resize_Width = %.03f, win_Resize_Height = %.03f" % \
                    (os.path.basename(libs.thisfile()), libs.linenum()
                    , win_Resize_Width, win_Resize_Height
                    ), file=sys.stderr)
    print()

    cv2.resizeWindow(window_1, win_Resize_Width, win_Resize_Height)
    #     cv2.resizeWindow(window_1, 600,600)

    #     cv2.namedWindow(window_1)
    #     cv2.namedWindow('window')
    '''###################
        mouse events
    ###################'''
    #ref https://www.pyimagesearch.com/2015/03/09/capturing-mouse-click-events-with-python-and-opencv/
    cv2.setMouseCallback(window_1, click_and_crop)
    #     cv2.setMouseCallback("image", click_and_crop)
    '''###################
        show
    ###################'''
    #     while True :
    #
    #         cv2.imshow(window_1, img_Orig_RGB)
    # #         cv2.imshow('window', img_Orig_RGB)
    #     #     cv2.imshow('window', img_Orig)
    #     #     cv2.imshow('window', I)
    #
    #         cv2.waitKey(0)
    #         cv2.destroyAllWindows()

    cv2.imshow('window', img_ForDisp)
    #     cv2.imshow('window', img_Orig_RGB)
    #     cv2.imshow('window', img_Orig)
    #     cv2.imshow('window', I)

    cv2.waitKey(0)
    cv2.destroyAllWindows()
def test_1():

    '''######################################
        ops        
    ######################################'''
    dpath_Ops_Images = "C:\\WORKS_2\\WS\\WS_Cake_IFM11\\iphone_to_upload"
#     C:\WORKS_2\WS\WS_Cake_IFM11\iphone_to_upload
    fname_Ops_Image = "2018-08-22_15-32-53_000.jpg"
#     fname_Ops_Image = "2018-08-22_15-42-10_000.jpg"
     
    fpath_Ops_Image = os.path.join(dpath_Ops_Images, fname_Ops_Image)

    '''###################
        get : exif data
    ###################'''
#     print(get_exif_of_image(fpath_Ops_Image)) 
# #     print get_exif_of_image(fpath_Ops_Image)
# #     print get_exif_of_image("sample.jpg")
    
    
    #ref https://stackoverflow.com/questions/15785719/how-to-print-a-dictionary-line-by-line-in-python
    
#     for item in dicOf_Exif:
#     
#         print(item)
#         
#     #/for item in dicOf_Exif:

#     for key in sorted(dicOf_Exif.keys()):
#     
#         print(key)
#         
#     #/for key in :

#     print("[%s:%d] dicOf_Exif['SubjectLocation'] => " % \
#             (os.path.basename(libs.thisfile()), libs.linenum()
#             
#             ), file=sys.stderr)
#     print(dicOf_Exif['SubjectLocation'])
    
    '''###################
        gps info
    ###################'''
    result = get_GPS_Data(fpath_Ops_Image)
            #(('N', 35, 35, 24.14), ('E', 139, 34, 48.01))
    
    print()
    print("[%s:%d] GPS data =>" % \
            (os.path.basename(libs.thisfile()), libs.linenum()
            
            ), file=sys.stderr)
    print(result)
    
    
    
    return
    
    dicOf_Exif = get_exif_of_image(fpath_Ops_Image)
    
    print()
    print("[%s:%d] dicOf_Exif['GPSInfo'] => " % \
            (os.path.basename(libs.thisfile()), libs.linenum()
            
            ), file=sys.stderr)
    print(dicOf_Exif['GPSInfo'])

    '''###################
        gps info
    ###################'''
    gps_Info = dicOf_Exif['GPSInfo']
    
    for item in gps_Info.keys():
#     for item in gps_Info:
    
        print("key => %d" % (item))
        print(gps_Info[item])
        print()
#         print("key => %d" % (item))
#         print(gps_Info[item])
#         print("%s => %s" % (item, gps_Info[item]))
#         print(item, type(item))
#                 #1 <class 'int'>
        
    #/for item in gps_Info:

    
    '''###################
        message
    ###################'''
    print()
    print("[%s:%d] test_1 =======================" % \
                    (os.path.basename(libs.thisfile()), libs.linenum()

                    ), file=sys.stderr)