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_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__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 __key_Inputs__EXECUTE__Save_SubImage(img_ForDisp):
    '''###################
        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[1]:refPt_End[1], refPt_Start[0]:refPt_End[0]
        #                 , refPt_Start[0] : refPt_Start[0] + 10
        #                 refPt_Start[0] : refPt_Start[0] + 10
        #                 , refPt_Start[1] : refPt_End[1]
    ]

    # file name
    fname = "subimage_%s.png" % 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_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
Пример #5
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)
def test_7__SubImage_RGB_Vals():
    '''###################
        message
    ###################'''
    print()
    print("[%s:%d] test_7__SubImage_RGB_Vals =======================" % \
        (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

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

    print("[%s:%d] width = %d, height = %d" % \
            (os.path.basename(libs.thisfile()), libs.linenum()
            , width, height
            ), file=sys.stderr)
    '''###################
        sub image        
    ###################'''
    # height, width
    img_Sub = img_ForDisp[19:69, 245:246]
    #     img_Sub = img_ForDisp[19:186, 245:246]

    # meta data
    height_Sub, width_Sub, channels_Sub = img_Sub.shape

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

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

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

                ), file=sys.stderr)
    print(img_Sub[0][0])
    '''###################
        get : RGB vals        
    ###################'''
    lo_Rs, lo_Gs, lo_Bs = test_7__SubImage_RGB_Vals__Get_RGB_Vals(img_Sub)

    #     print()
    #     print("[%s:%d] lo_Rs =>" % \
    #                 (os.path.basename(libs.thisfile()), libs.linenum()
    #
    #                 ), file=sys.stderr)
    #     print(lo_Rs)
    '''###################
        plot        
    ###################'''
    #     yax_vals = [200, 100,0]
    #     plt.bar(yax_vals, lo_Rs)
    # #     plt.bar(lo_Rs, yax_vals)
    # #     plt.bar(lo_Rs)
    # #     plt.plot(lo_Rs)
    #
    #     plt.show()

    #     objects = ('Python', 'C++', 'Java', 'Perl', 'Scala', 'Lisp')
    y_pos = np.arange(len(lo_Rs))
    #     y_pos = np.arange(len(objects))
    #     y_pos = [10, 20, 30]
    performance = lo_Rs
    #     performance = [30,8,6,4,2,1]
    #     performance = [10,8,6,4,2,1]

    #     performance.reverse()
    #     performance = [10,8,6,4,2,1]

    #     plt.bar(y_pos, performance, align='center', alpha=0.5)

    #     plt.plot(lo_Rs)
    #     plt.plot(lo_Bs)
    #     plt.plot(lo_Rs, lo_Bs)

    #     plt.xticks(y_pos, objects)
    #     plt.yticks([140, 180])

    #     plt.ylabel('Usage')
    #     plt.title('Programming language usage')
    #
    #     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=(140, 170))
    #
    #     plt.show()

    #     #ref https://stackoverflow.com/questions/4805048/how-to-get-different-colored-lines-for-different-plots-in-a-single-figure#4805456
    #     plotHandles = []
    #     labels = []
    #
    #     plotHandles.append(lo_Rs)
    #     labels.append("lo_Rs")
    #     plotHandles.append(lo_Gs)
    #     labels.append("lo_Gs")
    #
    #     plt.legend(plotHandles, labels, 'upper left',ncol=1)

    #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=(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)" % \
        (os.path.basename(libs.thisfile()), libs.linenum()
        , result, fpath_Save_Image
        ), file=sys.stderr)

    plt.show()

    #debug
    return
    '''######################################
        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)
    '''###################
        get : scaling        
    ###################'''
    scaling = test_7__SubImage_RGB_Vals__Get_Scaling(args)

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

    # validate
    scr_W = GetSystemMetrics(0)
    scr_H = GetSystemMetrics(1)
    '''###################
        resize image        
    ###################'''
    win_Resize_Width, win_Resize_Height = test_5__Resize_Image(
        width, height, scaling, scr_W, scr_H)
    '''###################
        disp : image
    ###################'''
    cv2.resizeWindow(window_1, win_Resize_Width, win_Resize_Height)
    '''###################
        mouse events
    ###################'''
    '''###################
        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
    ###################'''

    cv2.imshow('window', img_Sub)
    #     cv2.imshow('window', img_ForDisp)

    cv2.waitKey(0)
    cv2.destroyAllWindows()
def test_2__Color_Filtering_HSV():
    '''###################
        message
    ###################'''
    print()
    print("[%s:%d] test_2__Color_Filtering_HSV =======================" % \
        (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 = "img.20180728_084420.2018-07-24_05-14-26_000.jpg.1.png"
    #     fname_Ops_Image = "img.20180731_165432.2018-07-29_17-41-09_000.jpg.2.png"
    #     fname_Ops_Image = "img.20180731_165432.2018-07-29_17-41-09_000.jpg.1.png"
    #     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_Orig_RGB = cv2.cvtColor(img_Orig, cv2.COLOR_BGR2RGB)

    img_Orig_HSV = 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

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

    print("[%s:%d] width = %d, height = %d" % \
            (os.path.basename(libs.thisfile()), libs.linenum()
            , width, height
            ), file=sys.stderr)
    '''###################
        show image        
    ###################'''
    time_Label = libs.get_TimeLabel_Now()

    #     __test_2__Color_Filtering_HSV__Window_Ops(args, img_Orig)
    '''###################
        save image
    ###################'''
    #     __test_2__Color_Filtering_HSV__Save_Image(args, img_Orig)
    '''###################
        get : metadata
    ###################'''
    __test_2__Color_Filtering_HSV__Get_Metadata(args, img_ForDisp, time_Label,
                                                fname_Ops_Image)
    #     __test_2__Color_Filtering_HSV__Get_Metadata(args, img_ForDisp, time_Label)
    #     __test_2__Color_Filtering_HSV__Get_Metadata(args, img_ForDisp)
    '''###################
        filtering
    ###################'''
    #     __test_1__Color_Filtering__Exec_Filtering(img_ForDisp)
    '''###################
        window : close        
    ###################'''
    cv2.waitKey(0)

    cv2.destroyAllWindows()
def __test_2__Color_Filtering_HSV__Get_Metadata(args, img_Orig, time_Label,
                                                fname_Ops_Image):
    # def __test_2__Color_Filtering_HSV__Get_Metadata(args, img_Orig, time_Label):
    # def __test_2__Color_Filtering_HSV__Get_Metadata(args, img_Orig):

    img_HSV = cv2.cvtColor(img_Orig, cv2.COLOR_RGB2HSV)

    img_ForDisp = img_HSV

    height, width, channels = img_ForDisp.shape
    '''###################
        subimage
    ###################'''
    width_SubImage = 1

    #     x1 = 100
    x1 = 0
    x2 = x1 + width_SubImage
    #     x2 = x1 + 10
    #     x2 = x1 + 1
    #     y1 = 800
    y1 = 0
    #     y1 = 200
    y2 = height
    #     y2 = 400

    img_Sub = img_ForDisp[y1:y2  # y axis
                          , x1:x2  # x axis
                          ]

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

            ), file=sys.stderr)
    #     print(img_Sub[:10])

    for i in range(10):

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

    #/for i in range(10):

    # file name
#             % (libs.get_TimeLabel_Now()
    fname = "subimage_%s.%d-%d_%d-%d.(%s).png" \
            % (time_Label
               , x1, x2, y1, y2
               , fname_Ops_Image)
    #     fname = "subimage_%s.%d-%d_%d-%d.png" \
    #             % (time_Label
    #                , x1, x2, y1, y2)

    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)

    msg = "saving image ==> %s (%s)" %\
                        (result, fpath_Save_Image)

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

    libs.write_Log_2(
        msg_Log,
        dpath_LogFile=cons_ip.FilePaths.dpath_LogFile.value,
        fname_LogFile=cons_ip.FilePaths.fname_LogFile__Gradation.value,
        numOf_Return=1)

    #     libs.write_Log(msg_Log
    #                 , True)
    # #                 , cons_fx.FPath.dpath_LogFile.value
    # #                 , cons_fx.FPath.fname_LogFile.value
    # #                 , 1)
    '''###################
        metadata : prep        
    ###################'''
    maxOf_H = -1
    maxOf_S = -1
    maxOf_V = -1

    minOf_H = 999
    minOf_S = 999
    minOf_V = 999

    for row in img_Sub:
        #     for row in img_ForDisp:

        for pixel in row:

            H = pixel[0]
            S = pixel[1]
            V = pixel[2]

            # update : max
            if H > maxOf_H: maxOf_H = H
            if S > maxOf_S: maxOf_S = S
            if V > maxOf_V: maxOf_V = V

            # update : min
            if H < minOf_H: minOf_H = H
            if S < minOf_S: minOf_S = S
            if V < minOf_V: minOf_V = V

            #/if H > maxOf_H

        #/for pixel in row:

    #/for row in img_ForDisp:
    '''###################
        report        
    ###################'''
    msg = "maxOf_H => %d, maxOf_S => %d, maxOf_V => %d" % \
            (maxOf_H, maxOf_S, maxOf_V)

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

    libs.write_Log_2(
        msg_Log,
        dpath_LogFile=cons_ip.FilePaths.dpath_LogFile.value,
        fname_LogFile=cons_ip.FilePaths.fname_LogFile__Gradation.value,
        numOf_Return=1)
    #                 , 1)

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

    print("[%s:%d] minOf_H => %d, minOf_S => %d, minOf_V => %d" % \
            (os.path.basename(libs.thisfile()), libs.linenum()
            , minOf_H, minOf_S, minOf_V
            ), file=sys.stderr)
    '''###################
        write data : H        
    ###################'''
    lo_H = []
    lo_S = []
    lo_V = []

    # get : data
    for row in img_Sub:

        pixel = row[0]

        H = pixel[0]
        S = pixel[1]
        V = pixel[2]

        lo_H.append(H)
        lo_S.append(S)
        lo_V.append(V)

    #/for row in img_Sub:
    '''######################################
        write : data        
    ###################'''
    '''###################
        H        
    ###################'''
    lo_H_string = [str(x) for x in lo_H]

    msg = "\t".join(lo_H_string)

    msg_Log = "[%s / %s:%d] list of Hs =>" % \
            (
            libs.get_TimeLabel_Now()
            , os.path.basename(libs.thisfile()), libs.linenum()
            )

    libs.write_Log_2(
        msg_Log,
        dpath_LogFile=cons_ip.FilePaths.dpath_LogFile.value,
        fname_LogFile=cons_ip.FilePaths.fname_LogFile__Gradation.value,
        numOf_Return=1)
    #                 , numOf_Return = 0)

    msg_Log = "%s" % \
            (
                msg
            )

    libs.write_Log_2(
        msg_Log,
        dpath_LogFile=cons_ip.FilePaths.dpath_LogFile.value,
        fname_LogFile=cons_ip.FilePaths.fname_LogFile__Gradation.value,
        numOf_Return=2)
    #                 , numOf_Return = 1)
    '''###################
        S        
    ###################'''
    lo_S_string = [str(x) for x in lo_S]

    msg = "\t".join(lo_S_string)

    msg_Log = "[%s / %s:%d] list of Ss =>" % \
            (
            libs.get_TimeLabel_Now()
            , os.path.basename(libs.thisfile()), libs.linenum()
            )

    libs.write_Log_2(
        msg_Log,
        dpath_LogFile=cons_ip.FilePaths.dpath_LogFile.value,
        fname_LogFile=cons_ip.FilePaths.fname_LogFile__Gradation.value,
        numOf_Return=1)
    #                 , numOf_Return = 0)

    msg_Log = "%s" % \
            (
                msg
            )

    libs.write_Log_2(
        msg_Log,
        dpath_LogFile=cons_ip.FilePaths.dpath_LogFile.value,
        fname_LogFile=cons_ip.FilePaths.fname_LogFile__Gradation.value,
        numOf_Return=2)
    '''###################
        V        
    ###################'''
    lo_V_string = [str(x) for x in lo_V]

    msg = "\t".join(lo_V_string)

    msg_Log = "[%s / %s:%d] list of Vs =>" % \
            (
            libs.get_TimeLabel_Now()
            , os.path.basename(libs.thisfile()), libs.linenum()
            )

    libs.write_Log_2(
        msg_Log,
        dpath_LogFile=cons_ip.FilePaths.dpath_LogFile.value,
        fname_LogFile=cons_ip.FilePaths.fname_LogFile__Gradation.value,
        numOf_Return=1)
    #                 , numOf_Return = 0)

    msg_Log = "%s" % \
            (
                msg
            )

    libs.write_Log_2(
        msg_Log,
        dpath_LogFile=cons_ip.FilePaths.dpath_LogFile.value,
        fname_LogFile=cons_ip.FilePaths.fname_LogFile__Gradation.value,
        numOf_Return=2)
def __test_1__Color_Filtering__Exec_Filtering(img_ForDisp):

    img_Copy = deepcopy(img_ForDisp)
    '''###################
        process partial        
    ###################'''
    time_Label = libs.get_TimeLabel_Now()

    # horizontal
    x1 = 100
    x2 = 400

    # vertical
    y1 = 100
    y2 = 550
    #     y2 = 150

    # image : orig
    fname = "img_ForDisp_%s.%d-%d_%d-%d.png" \
            % (time_Label
               , x1, x2
               , y1, y2
               )

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

    result = cv2.imwrite(fpath_Save_Image, img_ForDisp)

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

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

    # image : copy
    #     leOf_Rows = len(img_Copy)
    '''###################
        filtering        
    ###################'''
    pixel_Target = img_Copy[y1][x1]

    threshold_Diff = 10

    for i in range(y1, y2):
        #     for i in range(100, 200):
        #     for i in range(100, lenOf_Rows):

        row = img_Copy[i]

        for j in range(x1, x2):
            #         for j in range(100, 200):
            #         for pixel in row:

            pixel = row[j]

            if pixel[0] < (pixel_Target[0] - threshold_Diff) \
                and pixel[1] < (pixel_Target[1] - threshold_Diff) \
                and pixel[2] < (pixel_Target[2] - threshold_Diff) :

                pixel[0] = 255
                pixel[1] = 255
                pixel[2] = 255

#             if pixel[0] < (pixel_Target[0] - threshold_Diff) : pixel[0] = 255
#             if pixel[1] < (pixel_Target[1] - threshold_Diff) : pixel[1] = 255
#             if pixel[2] < (pixel_Target[2] - threshold_Diff) : pixel[2] = 255

#/if pixel[0] < (pixel_Target[0] - threshold_Diff)

#             pixel[0] = 0
#             pixel[1] = 0
#             pixel[2] = 0

#/for pixel in row:

#/for row in img_Copy:

    fname = "img_Copy_%s.%d-%d_%d-%d.png" \
            % (time_Label
               , x1, x2
               , y1, y2
               )

    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_Copy)

    print("[%s:%d] image ==> saved : %s" % \
                    (os.path.basename(libs.thisfile()), libs.linenum()
                    , fpath_Save_Image
                    ), file=sys.stderr)
Пример #10
0
def anims_JS(request):
    '''###################
        time        
    ###################'''
    time_Exec_Start = time.time()
    '''###################
        vars
    ###################'''
    dic = {"message": "", "message_2": ""}

    render_Page = 'anims/anims/plain_anims.html'
    '''###################
        params
    ###################'''
    param = request.GET.get('param', False)

    #debug
    #     print("[%s:%d] param => %s" % \
    print("[%s:%d] param => %s ============================" % \
            (os.path.basename(libs.thisfile()), libs.linenum()
            , param
            ), file=sys.stderr)
    '''###################
        dispatch
    ###################'''
    if param == cons_ip.Anims_Params.PARAM__1_MOVE_LEAVES.value:  #if param == cons_fx.Tester.lo_Actions__BUSL__IDs[0].value
        '''###################
            PARAM__1_MOVE_LEAVES        
        ###################'''
        # call func
        (status, msg) = _anims_JS__1_Move_Leaves(request)

        dic['message'] += "move leaves"

        dic['message_2'] += "status = %d / msg = '%s'" % (status, msg)

    elif param == cons_ip.Anims_Params.PARAM__2_MOVE_LEAVES__V2.value:  #if param == cons_fx.Tester.lo_Actions__BUSL__IDs[0].value
        '''###################
            PARAM__1_MOVE_LEAVES__V2        
        ###################'''
        # call func
        #         (status, msg) = (1, "PARAM__2_MOVE_LEAVES__V2")
        (status, msg) = _anims_JS__2_Move_Leaves__V2(request)

        dic['message'] += "move leaves"

        dic['message_2'] += "status = %d / msg = '%s'" % (status, msg)

    elif param == cons_ip.Anims_Params.PARAM__3_CLUSTERS.value:  #if param == cons_fx.Tester.lo_Actions__BUSL__IDs[0].value
        '''###################
            PARAM__3_CLUSTERS        
        ###################'''
        # call func
        #         (status, msg) = (1, "PARAM__2_MOVE_LEAVES__V2")
        (status, msg) = _anims_JS__3_Clusters(request)
        #         (status, msg) = _anims_JS__2_Move_Leaves__V2(request)

        dic['message'] += "clusters"

        dic['message_2'] += "status = %d / msg = '%s'" % (status, msg)

    else:
        (status, msg) = (1, "unknown param : '%s'" % param)

        dic['message'] += "unknown param"

        dic['message_2'] += "status = %d / msg = '%s'" % (status, msg)
    '''###################
        time        
    ###################'''
    time_Exec_Elapsed = time.time() - time_Exec_Start

    dic['message_2'] += "(time = %s) (elapsed = %02.3f sec)" % \
                        (libs.get_TimeLabel_Now(), time_Exec_Elapsed)
    '''###################
        render
    ###################'''
    return render(request, render_Page, dic)
Пример #11
0
def _anims_JS__3_Clusters(request):
    '''###################
        tests
    ###################'''
    #     test_OpenCV__NewImage()
    '''###################
        ops
    ###################'''
    '''###################
        prep        
    ###################'''
    #     dpath_Image_File = param_Source_Dir
    dpath_Image_File = "C:\\WORKS_2\\WS\\WS_Others.Art\\JVEMV6\\46_art\\VIRTUAL\\Admin_Projects\\anims\\data\\data_images"
    #     dpath_Image_File = "C:\\WORKS_2\\WS\\WS_Others.Art\\JVEMV6\\46_art\\VIRTUAL\\Admin_Projects\\ip\\data\\data_images"

    #     fname_Image_File = param_Source_File
    #     fname_Image_File = "leaf-2.1.png"   # orig : C:\WORKS_2\WS\WS_Others.Art\JVEMV6\46_art\6_visual-arts\4_animations\1_\5_\images
    #     fname_Image_File = "2018-10-25_05-27-52_000.jpg"   # orig :
    fname_Image_File = "2018-10-25_05-27-52_000.(404x303).jpg"  # orig :

    fpath_Image_File = os.path.join(dpath_Image_File, fname_Image_File)

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

    # [views.py:608] fpath_Image_File = C:\WORKS_2\WS\WS_Others.Art\JVEMV6\46_art\VIRT
    # UAL\Admin_Projects\anims\data\data_images\2018-10-25_05-27-52_000.jpg (exists =
    # True)
    '''###################
        img : read
    ###################'''
    #ref http://peaceandhilightandpython.hatenablog.com/entry/2016/01/09/214333
    #ref alpha channel http://opencv.blog.jp/python/alpha_channel
    img = cv2.imread(fpath_Image_File, cv2.IMREAD_UNCHANGED)

    img_BGR = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
    img_HSV = cv2.cvtColor(img, cv2.COLOR_RGB2HSV)
    img_HSV_BGR = cv2.cvtColor(img_HSV, cv2.COLOR_RGB2BGR)

    #aa
    '''###################
        subimage
    ###################'''
    orgHeight, orgWidth = img.shape[:2]
    #     param_Start_X = 2437
    #     param_Start_Y = 217
    #
    #     param_End_X = 2537
    #     param_End_Y = 317
    #     param_Start_X = 237
    #     param_Start_Y = 150
    #
    #     param_End_X = 257
    #     param_End_Y = 160
    param_Start_X = 0
    param_Start_Y = 0

    param_End_X = orgWidth - 1
    param_End_Y = orgHeight - 1

    #ref lib_ip :: get_Corner_Images
    img_Sub = img[param_Start_Y:param_End_Y, param_Start_X:param_End_X]
    #     img_Sub = img[(height - corner_Length) : height - padding, \
    #                     0 + padding : corner_Length], # clp_LB
    '''###################
        paths
    ###################'''
    tokens = fname_Image_File.split(".")
    (h, w) = img.shape[:2]

    tokens_2 = os.path.splitext(fname_Image_File)

    tlabel = libs.get_TimeLabel_Now()

    # paths
    dir_Tmp = tlabel

    dpath_Tmp = os.path.join(dpath_Image_File, dir_Tmp)

    #ref mkdir https://www.tutorialspoint.com/python/os_mkdir.htm
    if not os.path.isdir(dpath_Tmp):
        os.mkdir(dpath_Tmp)

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

    else:

        print("[%s:%d] dir => exists : '%s'" % \
        (os.path.basename(libs.thisfile()), libs.linenum()
        , dpath_Tmp
        ), file=sys.stderr)
    '''###################
        TEST : copy image to the new dir
    ###################'''
    #     fname_Dst = "%s.(rotate=%d).%s.(center=%d,%d).%s" \
    #     fname_Dst = "%s.(%s).%s" \
    fname_Dst_Orig = "%s.(orig).(%s)%s" \
            % (tokens_2[0], tlabel, tokens_2[1])
    fname_Dst_BGR = "%s.(BGR).(%s)%s" \
            % (tokens_2[0], tlabel, tokens_2[1])
    fname_Dst_HSV = "%s.(HSV).(%s)%s" \
            % (tokens_2[0], tlabel, tokens_2[1])
    fname_Dst_HSV_BGR = "%s.(HSV_BGR).(%s)%s" \
            % (tokens_2[0], tlabel, tokens_2[1])

    fname_Dst_Sub = "%s.(sub.%d,%d-%d,%d).(%s)%s" \
            % (tokens_2[0]
               , param_Start_X, param_Start_Y
               , param_End_X, param_End_Y
               , tlabel, tokens_2[1])

    fpath_Dst__Orig = os.path.join(dpath_Image_File, dir_Tmp, fname_Dst_Orig)
    fpath_Dst__BGR = os.path.join(dpath_Image_File, dir_Tmp, fname_Dst_BGR)
    fpath_Dst__HSV = os.path.join(dpath_Image_File, dir_Tmp, fname_Dst_HSV)
    fpath_Dst__HSV_BGR = os.path.join(dpath_Image_File, dir_Tmp,
                                      fname_Dst_HSV_BGR)
    fpath_Dst__Sub = os.path.join(dpath_Image_File, dir_Tmp, fname_Dst_Sub)

    # #     res = cv2.imwrite(fpath_Dst, img_BGR)
    #     res = cv2.imwrite(fpath_Dst__Orig, img)
    #     res = cv2.imwrite(fpath_Dst__BGR, img_BGR)
    #     res = cv2.imwrite(fpath_Dst__HSV, img_HSV)
    #     res = cv2.imwrite(fpath_Dst__HSV_BGR, img_HSV_BGR)
    #     res = cv2.imwrite(fpath_Dst__Sub, img_Sub)
    # #     res = cv2.imwrite(fpath_Dst, img)
    # #     cv2.imwrite(fpath_Dst, rotated)
    #
    #     print("[%s:%d] cv2.imwrite => '%s'" % \
    #             (os.path.basename(libs.thisfile()), libs.linenum()
    #             , res
    #             ), file=sys.stderr)
    '''###################
        clusters
    ###################'''
    _anims_JS__3_Clusters__Clusters(request, img_Sub, fpath_Dst__Sub)
    #     _anims_JS__3_Clusters__Clusters(request, img, fpath_Dst__Sub)
    #     _anims_JS__3_Clusters__Clusters(request, img_Sub, fpath_Dst__Sub)
    #aa
    '''###################
        return        
    ###################'''
    status = 1

    msg = "_anims_JS__3_Clusters"

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

    return (status, msg)
Пример #12
0
def _anims_JS__1_Move_Leaves__Test_1_Resize(request):
    '''###################
        prep : params
            main.js :: _anims_Action_LinkTo__1(_param)
            , option_tick_move_X : _option_tick_move_X
            , option_tick_move_Y : _option_tick_move_Y
            
            , opt_rotate_Start : _opt_rotate_Start
            , opt_rotate_End : _opt_rotate_End

    ###################'''
    param_Loc_Start_X = request.GET.get('option_loc_start_X', False)
    param_Loc_Start_Y = request.GET.get('option_loc_start_Y', False)

    param_Source_Dir = request.GET.get('opt_source_Dir', False)
    param_Source_File = request.GET.get('opt_source_File', False)

    param_Cut_Width = request.GET.get('opt_cut_width', False)
    param_Cut_Height = request.GET.get('opt_cut_height', False)

    param_Rotate_Start = request.GET.get('opt_rotate_Start', False)
    param_Rotate_End = request.GET.get('opt_rotate_End', False)
    param_Rotate_Tick = request.GET.get('opt_rotate_Tick', False)

    print("[%s:%d] param_Rotate_Tick => %s" % \
        (os.path.basename(libs.thisfile()), libs.linenum()
        , param_Rotate_Tick
        ), file=sys.stderr)
    # modify
    # ref tertiary https://stackoverflow.com/questions/394809/does-python-have-a-ternary-conditional-operator
    param_Loc_Start_X = 0 if (param_Loc_Start_X
                              == False) else int(param_Loc_Start_X)
    param_Loc_Start_Y = 0 if (param_Loc_Start_Y
                              == False) else int(param_Loc_Start_Y)

    param_Cut_Width = 100 if (param_Cut_Width
                              == False) else int(param_Cut_Width)
    param_Cut_Height = 100 if (param_Cut_Height
                               == False) else int(param_Cut_Height)

    param_Rotate_Start = 0 if (param_Rotate_Start
                               == False) else int(param_Rotate_Start)
    param_Rotate_End = 45 if (param_Rotate_End
                              == False) else int(param_Rotate_End)
    param_Rotate_Tick = 5 if (param_Rotate_Tick
                              == False) else int(param_Rotate_Tick)

    param_Source_Dir = cons_ip.FilePaths.dpath_Anims_Image_Files.value \
                    if (param_Source_Dir == False) else param_Source_Dir

    param_Source_File = cons_ip.FilePaths.fname_Anims_Image_Files.value \
                    if (param_Source_File == False) else param_Source_File


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

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

    #     print("[%s:%d] param_Loc_Start_X = %d, param_Loc_Start_Y = %d" % \
    #         (os.path.basename(libs.thisfile()), libs.linenum()
    #         , param_Loc_Start_X, param_Loc_Start_Y
    #         ), file=sys.stderr)
    '''###################
        prep        
    ###################'''
    dpath_Image_File = param_Source_Dir
    #     dpath_Image_File = "C:\\WORKS_2\\WS\\WS_Others.Art\\JVEMV6\\46_art\\VIRTUAL\\Admin_Projects\\anims\\data\\data_images"
    #     dpath_Image_File = "C:\\WORKS_2\\WS\\WS_Others.Art\\JVEMV6\\46_art\\VIRTUAL\\Admin_Projects\\ip\\data\\data_images"

    fname_Image_File = param_Source_File
    #     fname_Image_File = "leaf-2.1.png"   # orig : C:\WORKS_2\WS\WS_Others.Art\JVEMV6\46_art\6_visual-arts\4_animations\1_\5_\images

    fpath_Image_File = os.path.join(dpath_Image_File, fname_Image_File)

    print("[%s:%d] fpath_Image_File = %s (exists = %s)" % \
        (os.path.basename(libs.thisfile()), libs.linenum()
        , fpath_Image_File, os.path.isfile(fpath_Image_File)
        ), file=sys.stderr)
    '''###################
        op        
    ###################'''
    '''###################
        img : read
    ###################'''
    #ref http://peaceandhilightandpython.hatenablog.com/entry/2016/01/09/214333
    #ref alpha channel http://opencv.blog.jp/python/alpha_channel
    img = cv2.imread(fpath_Image_File, cv2.IMREAD_UNCHANGED)
    #     img = cv2.imread(fpath_Image_File)
    #     img = cv2.imread(fpath_Image_File, cv2.IMREAD_COLOR)

    #     orgHeight, orgWidth = img.shape[:2]
    #     size = (int(orgWidth/2), int(orgHeight/2))
    # #     size = (int(orgHeight/2), int(orgWidth/2))
    #
    # #     size = (orgHeight/2, orgWidth/2)
    #
    #     halfImg = cv2.resize(img, size)
    #
    #     tokens = fname_Image_File.split(".")
    #     fname_Half = "%s.%s.(half).%s.%s" \
    #             % (tokens[0], tokens[1], libs.get_TimeLabel_Now(), tokens[2])
    #
    #     cv2.imwrite(os.path.join(dpath_Image_File, fname_Half), halfImg)
    #     cv2.imwrite('half.jpg', halfImg)
    '''###################
        rotate        
    ###################'''
    tokens = fname_Image_File.split(".")
    (h, w) = img.shape[:2]

    tokens_2 = os.path.splitext(fname_Image_File)

    tlabel = libs.get_TimeLabel_Now()

    # paths
    dir_Tmp = tlabel

    dpath_Tmp = os.path.join(dpath_Image_File, dir_Tmp)

    #ref mkdir https://www.tutorialspoint.com/python/os_mkdir.htm
    if not os.path.isdir(dpath_Tmp):
        os.mkdir(dpath_Tmp)

    #ref step https://www.pythoncentral.io/pythons-range-function-explained/
#     for i in range(param_Rotate_Start, param_Rotate_End):
    for i in range(param_Rotate_Start, param_Rotate_End, param_Rotate_Tick):
        #     for i in range(0, 10):
        #     for i in range(0, 5):

        #         angle = i * 5
        angle = i
        scale = 1.0

        #ref radians https://docs.scipy.org/doc/numpy/reference/generated/numpy.radians.html
        span = int((370 - w / 2) * np.sin(np.radians(angle)))
        span_w = int((370 - w / 2) * np.cos(np.radians(angle)))

        center = (w / 2 + span_w, h / 2 + span)
        #         center = (w / 2, h / 2 + span)
        #         center = (w / 2, h / 2 - span)
        #         (h, w) = img.shape[:2]
        #         center = (w / 2, h / 2)

        #         # paths
        #         dir_Tmp = tlabel
        #
        #         dpath_Tmp = os.path.join(dpath_Image_File, dir_Tmp)
        #
        #         #ref mkdir https://www.tutorialspoint.com/python/os_mkdir.htm
        #         if not os.path.isdir(dpath_Tmp) :
        #             os.mkdir(dpath_Tmp)
        #
        fname_Dst = "%s.(rotate=%d).%s.(center=%d,%d).%s" \
                % (tokens_2[0], angle, tlabel, center[0], center[1], tokens_2[1])
        #         fname_Dst = "%s.%s.(rotate=%d).%s.(center=%d,%d).%s" \
        #                 % (tokens[0], tokens[1], angle, tlabel, center[0], center[1], tokens[2])
        #                 % (tokens[0], tokens[1], angle, tlabel, tokens[2])
        #                 % (tokens[0], tokens[1], angle, libs.get_TimeLabel_Now(), tokens[2])

        fpath_Dst = os.path.join(dpath_Image_File, dir_Tmp, fname_Dst)
        #         fpath_Dst = os.path.join(dpath_Image_File, fname_Dst)

        _anims_JS__1_Move_Leaves__Test_1_Resize__exec(angle, scale, img,
                                                      center, fpath_Dst)
    '''###################
        return        
    ###################'''
    status = 1

    msg = "file created at : %s" % dpath_Tmp

    return (status, msg)
Пример #13
0
def test_OpenCV__NewImage():
    '''###################
        prep        
    ###################'''
    dpath_Image_File = "C:\\WORKS_2\\WS\\WS_Others.Art\\JVEMV6\\46_art\\VIRTUAL\\Admin_Projects\\anims\\data\\data_images"
    #     dpath_Image_File = "C:\\WORKS_2\\WS\\WS_Others.Art\\JVEMV6\\46_art\\VIRTUAL\\Admin_Projects\\ip\\data\\data_images"

    fname_Image_File = "leaf-2.1.png"  # orig : C:\WORKS_2\WS\WS_Others.Art\JVEMV6\46_art\6_visual-arts\4_animations\1_\5_\images

    fpath_Image_File = os.path.join(dpath_Image_File, fname_Image_File)

    print("[%s:%d] fpath_Image_File = %s (exists = %s)" % \
        (os.path.basename(libs.thisfile()), libs.linenum()
        , fpath_Image_File, os.path.isfile(fpath_Image_File)
        ), file=sys.stderr)
    '''###################
        prep : image
    ###################'''
    #ref http://peaceandhilightandpython.hatenablog.com/entry/2016/01/09/214333
    #ref alpha channel http://opencv.blog.jp/python/alpha_channel
    img = cv2.imread(fpath_Image_File, cv2.IMREAD_UNCHANGED)

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

            ), file=sys.stderr)
    print(img.shape)
    print()
    '''###################
        ops
    ###################'''
    tokens = fname_Image_File.split(".")
    (h, w) = img.shape[:2]

    tlabel = libs.get_TimeLabel_Now()

    fname_Dst = "%s.%s.(test_OpenCV__NewImage).%s.%s" \
        % (tokens[0], tokens[1], tlabel, tokens[2])

    fpath_Dst = os.path.join(dpath_Image_File, fname_Dst)

    print("[%s:%d] fname_Dst => %s" % \
        (os.path.basename(libs.thisfile()), libs.linenum()
        , fname_Dst
        ), file=sys.stderr)
    '''###################
        image : blank        
    ###################'''
    # blank image
    #ref https://stackoverflow.com/questions/12881926/create-a-new-rgb-opencv-image-using-python
    blank_image = np.zeros((img.shape[0], img.shape[1], 4), np.uint8)

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

                ), file=sys.stderr)
    print(blank_image.shape)

    # shape
    (h2, w2) = blank_image.shape[:2]

    # coloring
    # BGRA : A --> 0 for transpanrent
    #     blank_image[:, 0 : int(0.5*w2)] = (255, 0, 0, 255)
    #     blank_image[:, 0 : int(0.5*w2)] = (100, 100, 100, 200)
    #     blank_image[:, 0 : int(0.5*w2)] = (100, 100, 100, 100)
    #     blank_image[:, 0 : int(0.5*w2)] = (255,0,0, 0)
    #     blank_image[:,0:0.5*w2] = (255,0,0, 0)
    #     blank_image[:,0:0.5*width] = (255,0,0, 0)
    #     blank_image[:, :] = (255, 0, 0, 0)
    #     blank_image[:, :] = (255, 0, 0)

    # copy a partial image of img to blank_image
    cut_height = 120
    cut_width = 120

    blank_image[100 : 100 + cut_height, 250 : 250 + cut_width] \
            = img[150:270, 300:420]
    #     blank_image[150:270, 300:420] = img[150:270, 300:420]

    #write
    cv2.imwrite(fpath_Dst, blank_image)