Beispiel #1
0
def MGrab():
    rootdir = "Scanner"
    try:
        if not os.path.exists(rootdir):
            os.makedirs(rootdir)
    except OSError:
        print('Error: Creating directory. ' + rootdir)
    # Allocate defaults.
    MilApplication = MIL.MappAlloc(MIL.MIL_TEXT("M_DEFAULT"), MIL.M_DEFAULT,
                                   None)
    MilSystem = MIL.MsysAlloc(MIL.M_DEFAULT, MIL.M_SYSTEM_HOST, MIL.M_DEV0,
                              MIL.M_DEFAULT, None)
    MilDisplay_0 = MIL.MdispAlloc(MilSystem, MIL.M_DEFAULT,
                                  MIL.MIL_TEXT("M_DEFAULT"), MIL.M_DEFAULT,
                                  None)
    MilDisplay_1 = MIL.MdispAlloc(MilSystem, MIL.M_DEFAULT,
                                  MIL.MIL_TEXT("M_DEFAULT"), MIL.M_DEFAULT,
                                  None)
    MilDigitizer_0 = MIL.MdigAlloc(MilSystem, MIL.M_DEV0,
                                   MIL.MIL_TEXT("M_DEFAULT"), MIL.M_DEFAULT,
                                   None)
    MilDigitizer_1 = MIL.MdigAlloc(MilSystem, MIL.M_DEV1,
                                   MIL.MIL_TEXT("M_DEFAULT"), MIL.M_DEFAULT,
                                   None)

    SizeX_0 = MIL.MdigInquire(MilDigitizer_0, MIL.M_SIZE_X, None)
    SizeY_0 = MIL.MdigInquire(MilDigitizer_0, MIL.M_SIZE_Y, None)

    SizeX_1 = MIL.MdigInquire(MilDigitizer_1, MIL.M_SIZE_X, None)
    SizeY_1 = MIL.MdigInquire(MilDigitizer_1, MIL.M_SIZE_Y, None)

    SizeBand_Par = MIL.MdigInquire(MilDigitizer_0, MIL.M_SIZE_BAND, None)
    SizeX_Par = MIL.MdigInquire(MilDigitizer_0, MIL.M_SIZE_X, None)
    SizeY_Par = MIL.MdigInquire(MilDigitizer_0, MIL.M_SIZE_Y, None)

    MilImageParent = MIL.MbufAllocColor(
        MilSystem, SizeBand_Par, SizeX_Par * 2, SizeY_Par, 8 + MIL.M_UNSIGNED,
        MIL.M_IMAGE + MIL.M_PROC + MIL.M_DISP + MIL.M_GRAB, None)

    MIL.MbufClear(MilImageParent, MIL.M_COLOR_BLACK)

    # MilImageDisp_0 = MIL.MbufAllocColor(MilSystem,
    #                                   SizeBand_0,
    #                                   SizeX_0,
    #                                   SizeY_0,
    #                                   8 + MIL.M_UNSIGNED,
    #                                   MIL.M_IMAGE +
    #                                   MIL.M_PROC + MIL.M_DISP + MIL.M_GRAB,
    #                                   None)

    MilImageDisp_0 = MIL.MbufChildColor2d(MilImageParent, MIL.M_ALL_BANDS, 0,
                                          0, SizeX_0, SizeY_0, None)

    MIL.MbufClear(MilImageDisp_0, MIL.M_COLOR_BLACK)

    # MilImageDisp_1 = MIL.MbufAllocColor(MilSystem,
    #                                     SizeBand_1,
    #                                     SizeX_1,
    #                                     SizeY_1,
    #                                     8 + MIL.M_UNSIGNED,
    #                                     MIL.M_IMAGE +
    #                                     MIL.M_PROC + MIL.M_DISP + MIL.M_GRAB,
    #                                     None)
    #
    MilImageDisp_1 = MIL.MbufChildColor2d(MilImageParent, MIL.M_ALL_BANDS,
                                          SizeX_0, 0, SizeX_1, SizeY_1, None)

    MIL.MbufClear(MilImageDisp_1, MIL.M_COLOR_BLACK)
    MIL.MdispSelect(MilDisplay_0, MilImageDisp_0)
    MIL.MdispSelect(MilDisplay_1, MilImageDisp_1)

    # Print a message.
    print("-----------------------------\n")

    for i in range(100):
        MIL.MdigGrabContinuous(MilDigitizer_0, MilImageDisp_0)
        MIL.MdigGrabContinuous(MilDigitizer_1, MilImageDisp_1)

        # Halt continuous grab.
        MIL.MdigHalt(MilDigitizer_0)
        MIL.MdigHalt(MilDigitizer_1)
        # MIL.MbufExport(MIL.MIL_TEXT("0_FileName{i}.tif".format(i=i)), MIL.M_TIFF, MilImageDisp_0)
        # MIL.MbufExport(MIL.MIL_TEXT("1_FileName{i}.tif".format(i=i)), MIL.M_TIFF, MilImageDisp_1)
        MIL.MbufExport(
            MIL.MIL_TEXT("{}/F_FileName{i}.tif".format(rootdir, i=i)),
            MIL.M_TIFF, MilImageParent)

    MIL.MbufFree(MilImageDisp_0)
    MIL.MbufFree(MilImageDisp_1)
    MIL.MbufFree(MilImageParent)
    MIL.MdispFree(MilDisplay_0)
    MIL.MdispFree(MilDisplay_1)
    MIL.MdigFree(MilDigitizer_0)
    MIL.MdigFree(MilDigitizer_1)
    MIL.MsysFree(MilSystem)
    MIL.MappFree(MilApplication)

    return
Beispiel #2
0
def MGrab():
    # Allocate defaults.
    MilApplication = MIL.MappAlloc(MIL.MIL_TEXT("M_DEFAULT"), MIL.M_DEFAULT,
                                   None)
    MilSystem = MIL.MsysAlloc(MIL.M_DEFAULT, MIL.M_SYSTEM_HOST, MIL.M_DEV0,
                              MIL.M_DEFAULT, None)
    MilDisplay_0 = MIL.MdispAlloc(MilSystem, MIL.M_DEFAULT,
                                  MIL.MIL_TEXT("M_DEFAULT"), MIL.M_DEFAULT,
                                  None)
    MilDisplay_1 = MIL.MdispAlloc(MilSystem, MIL.M_DEFAULT,
                                  MIL.MIL_TEXT("M_DEFAULT"), MIL.M_DEFAULT,
                                  None)
    MilDigitizer_0 = MIL.MdigAlloc(MilSystem, MIL.M_DEV0,
                                   MIL.MIL_TEXT("M_DEFAULT"), MIL.M_DEFAULT,
                                   None)
    MilDigitizer_1 = MIL.MdigAlloc(MilSystem, MIL.M_DEV1,
                                   MIL.MIL_TEXT("M_DEFAULT"), MIL.M_DEFAULT,
                                   None)

    SizeBand_0 = MIL.MdigInquire(MilDigitizer_0, MIL.M_SIZE_BAND, None)
    SizeX_0 = MIL.MdigInquire(MilDigitizer_0, MIL.M_SIZE_X, None)
    SizeY_0 = MIL.MdigInquire(MilDigitizer_0, MIL.M_SIZE_Y, None)

    SizeBand_1 = MIL.MdigInquire(MilDigitizer_0, MIL.M_SIZE_BAND, None)
    SizeX_1 = MIL.MdigInquire(MilDigitizer_0, MIL.M_SIZE_X, None)
    SizeY_1 = MIL.MdigInquire(MilDigitizer_0, MIL.M_SIZE_Y, None)

    MilImageDisp_0 = MIL.MbufAllocColor(
        MilSystem, SizeBand_0, SizeX_0, SizeY_0, 8 + MIL.M_UNSIGNED,
        MIL.M_IMAGE + MIL.M_PROC + MIL.M_DISP + MIL.M_GRAB, None)

    MIL.MbufClear(MilImageDisp_0, MIL.M_COLOR_BLACK)

    MilImageDisp_1 = MIL.MbufAllocColor(
        MilSystem, SizeBand_1, SizeX_1, SizeY_1, 8 + MIL.M_UNSIGNED,
        MIL.M_IMAGE + MIL.M_PROC + MIL.M_DISP + MIL.M_GRAB, None)

    MIL.MbufClear(MilImageDisp_1, MIL.M_COLOR_BLACK)
    MIL.MdispSelect(MilDisplay_0, MilImageDisp_0)
    MIL.MdispSelect(MilDisplay_1, MilImageDisp_1)

    # Print a message.
    print("-----------------------------\n")

    for i in range(100):
        MIL.MdigGrabContinuous(MilDigitizer_0, MilImageDisp_0)
        MIL.MdigGrabContinuous(MilDigitizer_1, MilImageDisp_1)

        # Halt continuous grab.
        MIL.MdigHalt(MilDigitizer_0)
        MIL.MdigHalt(MilDigitizer_1)
        MIL.MbufExport(MIL.MIL_TEXT("0_FileName{i}.tif".format(i=i)),
                       MIL.M_TIFF, MilImageDisp_0)
        MIL.MbufExport(MIL.MIL_TEXT("1_FileName{i}.tif".format(i=i)),
                       MIL.M_TIFF, MilImageDisp_1)

    MIL.MbufFree(MilImageDisp_0)
    MIL.MbufFree(MilImageDisp_1)
    MIL.MdispFree(MilDisplay_0)
    MIL.MdispFree(MilDisplay_1)
    MIL.MdigFree(MilDigitizer_0)
    MIL.MdigFree(MilDigitizer_1)
    MIL.MsysFree(MilSystem)
    MIL.MappFree(MilApplication)

    return
Beispiel #3
0
def MGrab(ScannerID, nImage):
    ## Directory Check
    rootdir = "Scanner/{}".format(ScannerID)
    try:
        if not os.path.exists(rootdir):
            os.makedirs(rootdir)
    except OSError:
        print('Error: Creating directory. ' + rootdir)

    # Allocate defaults.
    MilApplication = MIL.MappAlloc(MIL.MIL_TEXT("M_DEFAULT"), MIL.M_DEFAULT,
                                   None)
    MilSystem = MIL.MsysAlloc(MIL.M_DEFAULT, MIL.M_SYSTEM_HOST, MIL.M_DEV0,
                              MIL.M_DEFAULT, None)
    MilDisplay_0 = MIL.MdispAlloc(MilSystem, MIL.M_DEFAULT,
                                  MIL.MIL_TEXT("M_DEFAULT"), MIL.M_DEFAULT,
                                  None)
    MilDisplay_1 = MIL.MdispAlloc(MilSystem, MIL.M_DEFAULT,
                                  MIL.MIL_TEXT("M_DEFAULT"), MIL.M_DEFAULT,
                                  None)
    MilDigitizer_0 = MIL.MdigAlloc(MilSystem, MIL.M_DEV0,
                                   MIL.MIL_TEXT("M_DEFAULT"), MIL.M_DEFAULT,
                                   None)
    MilDigitizer_1 = MIL.MdigAlloc(MilSystem, MIL.M_DEV1,
                                   MIL.MIL_TEXT("M_DEFAULT"), MIL.M_DEFAULT,
                                   None)

    SizeBand_0 = MIL.MdigInquire(MilDigitizer_0, MIL.M_SIZE_BAND, None)
    SizeX_0 = MIL.MdigInquire(MilDigitizer_0, MIL.M_SIZE_X, None)
    SizeY_0 = MIL.MdigInquire(MilDigitizer_0, MIL.M_SIZE_Y, None)

    SizeBand_1 = MIL.MdigInquire(MilDigitizer_0, MIL.M_SIZE_BAND, None)
    SizeX_1 = MIL.MdigInquire(MilDigitizer_0, MIL.M_SIZE_X, None)
    SizeY_1 = MIL.MdigInquire(MilDigitizer_0, MIL.M_SIZE_Y, None)

    MilImageDisp_0 = MIL.MbufAllocColor(
        MilSystem, SizeBand_0, SizeX_0, SizeY_0, 8 + MIL.M_UNSIGNED,
        MIL.M_IMAGE + MIL.M_PROC + MIL.M_DISP + MIL.M_GRAB, None)

    MIL.MbufClear(MilImageDisp_0, MIL.M_COLOR_BLACK)

    MilImageDisp_1 = MIL.MbufAllocColor(
        MilSystem, SizeBand_1, SizeX_1, SizeY_1, 8 + MIL.M_UNSIGNED,
        MIL.M_IMAGE + MIL.M_PROC + MIL.M_DISP + MIL.M_GRAB, None)

    MIL.MbufClear(MilImageDisp_1, MIL.M_COLOR_BLACK)
    MIL.MdispSelect(MilDisplay_0, MilImageDisp_0)
    MIL.MdispSelect(MilDisplay_1, MilImageDisp_1)

    # Print a message.
    print("-----------------------------\n")

    for i in range(nImage):
        MIL.MdigGrabContinuous(MilDigitizer_0, MilImageDisp_0)
        MIL.MdigGrabContinuous(MilDigitizer_1, MilImageDisp_1)

        # Halt continuous grab.
        MIL.MdigHalt(MilDigitizer_0)
        MIL.MdigHalt(MilDigitizer_1)
        MIL.MbufExport(MIL.MIL_TEXT("{}/0_FileName{}.tif".format(rootdir, i)),
                       MIL.M_TIFF, MilImageDisp_0)
        MIL.MbufExport(MIL.MIL_TEXT("{}/1_FileName{}.tif".format(rootdir, i)),
                       MIL.M_TIFF, MilImageDisp_1)

    MIL.MbufFree(MilImageDisp_0)
    MIL.MbufFree(MilImageDisp_1)
    MIL.MdispFree(MilDisplay_0)
    MIL.MdispFree(MilDisplay_1)
    MIL.MdigFree(MilDigitizer_0)
    MIL.MdigFree(MilDigitizer_1)
    MIL.MsysFree(MilSystem)
    MIL.MappFree(MilApplication)

    return
Beispiel #4
0
def MdigProcessExample():
    # Allocate defaults.
    MilApplication = MIL.MappAlloc(MIL.MIL_TEXT("M_DEFAULT"), MIL.M_DEFAULT,
                                   None)
    MilSystem = MIL.MsysAlloc(MIL.M_DEFAULT, MIL.M_SYSTEM_HOST, MIL.M_DEV0,
                              MIL.M_DEFAULT, None)
    MilDisplay = MIL.MdispAlloc(MilSystem, MIL.M_DEFAULT,
                                MIL.MIL_TEXT("M_DEFAULT"), MIL.M_DEFAULT, None)
    MilDisplay_1 = MIL.MdispAlloc(MilSystem, MIL.M_DEFAULT,
                                  MIL.MIL_TEXT("M_DEFAULT"), MIL.M_DEFAULT,
                                  None)
    MilDisplay_2 = MIL.MdispAlloc(MilSystem, MIL.M_DEFAULT,
                                  MIL.MIL_TEXT("M_DEFAULT"), MIL.M_DEFAULT,
                                  None)
    MilDigitizer = MIL.MdigAlloc(MilSystem, MIL.M_DEV0,
                                 MIL.MIL_TEXT("M_DEFAULT"), MIL.M_DEFAULT,
                                 None)
    MilDigitizer_1 = MIL.MdigAlloc(MilSystem, MIL.M_DEV1,
                                   MIL.MIL_TEXT("M_DEFAULT"), MIL.M_DEFAULT,
                                   None)

    SizeX = MIL.MdigInquire(MilDigitizer, MIL.M_SIZE_X, None)
    SizeY = MIL.MdigInquire(MilDigitizer, MIL.M_SIZE_Y, None)

    MilImageDisp = MIL.MbufAllocColor(
        MilSystem, 3, SizeX * 2, SizeY, 8 + MIL.M_UNSIGNED,
        MIL.M_IMAGE + MIL.M_PROC + MIL.M_DISP + MIL.M_GRAB, None)

    MIL.MbufClear(MilImageDisp, MIL.M_COLOR_BLACK)
    MIL.MdispSelect(MilDisplay, MilImageDisp)

    MilImageDisp_0 = MIL.MbufChildColor2d(MilImageDisp, MIL.M_ALL_BANDS, 0, 0,
                                          SizeX, SizeY, None)
    MIL.MbufClear(MilImageDisp_0, MIL.M_COLOR_BLACK)

    MilImageDisp_1 = MIL.MbufChildColor2d(MilImageDisp, MIL.M_ALL_BANDS, SizeX,
                                          0, SizeX, SizeY, None)
    MIL.MbufClear(MilImageDisp_1, MIL.M_COLOR_BLACK)
    MIL.MdispSelect(MilDisplay, MilImageDisp_0)
    MIL.MdispSelect(MilDisplay_1, MilImageDisp_1)
    MIL.MdispSelect(MilDisplay_2, MilImageDisp)

    # Print a message.
    print("\nMULTIPLE BUFFERED PROCESSING.")
    print("-----------------------------\n")

    # Grab continuously on the display and wait for a key press
    MIL.MdigGrabContinuous(MilDigitizer, MilImageDisp_0)
    MIL.MdigGrabContinuous(MilDigitizer_1, MilImageDisp_1)
    get_input("Press <Enter> to start processing.\r")

    # Halt continuous grab.
    MIL.MdigHalt(MilDigitizer)
    MIL.MdigHalt(MilDigitizer_1)

    # Allocate the grab buffers and clear them.
    MilGrabBufferList = (MIL.MIL_ID * BUFFERING_SIZE_MAX)()
    MilGrabBufferListSize = 0
    MIL.MappControl(MIL.M_DEFAULT, MIL.M_ERROR, MIL.M_PRINT_DISABLE)
    for n in range(0, BUFFERING_SIZE_MAX):
        MilGrabBufferList[n] = (MIL.MbufAllocColor(
            MilSystem, 3, SizeX, SizeY, 8 + MIL.M_UNSIGNED,
            MIL.M_IMAGE + MIL.M_GRAB + MIL.M_PROC, None))
        if (MilGrabBufferList[n] != MIL.M_NULL):
            MIL.MbufClear(MilGrabBufferList[n], 0xFF)
            MilGrabBufferListSize += 1
        else:
            break
    MilGrabBufferList_1 = (MIL.MIL_ID * BUFFERING_SIZE_MAX)()
    MilGrabBufferListSize_1 = 0
    for n in range(0, BUFFERING_SIZE_MAX):
        MilGrabBufferList_1[n] = (MIL.MbufAllocColor(
            MilSystem, 3, SizeX, SizeY, 8 + MIL.M_UNSIGNED,
            MIL.M_IMAGE + MIL.M_GRAB + MIL.M_PROC, None))
        if (MilGrabBufferList_1[n] != MIL.M_NULL):
            MIL.MbufClear(MilGrabBufferList_1[n], 0xFF)
            MilGrabBufferListSize_1 += 1
        else:
            break
    MIL.MappControl(MIL.M_DEFAULT, MIL.M_ERROR, MIL.M_PRINT_ENABLE)

    # Initialize the user's processing function data structure.
    UserHookData = HookDataStruct(MilDigitizer, MilImageDisp_0, 0,
                                  MilImageDisp)
    UserHookData_1 = HookDataStruct(MilDigitizer_1, MilImageDisp_1, 0, 0)

    # Start the processing. The processing function is called with every frame grabbed.
    ProcessingFunctionPtr = MIL.MIL_DIG_HOOK_FUNCTION_PTR(ProcessingFunction)
    ProcessingFunctionPtr_1 = MIL.MIL_DIG_HOOK_FUNCTION_PTR(
        ProcessingFunction_1)
    MIL.MdigProcess(MilDigitizer, MilGrabBufferList, MilGrabBufferListSize,
                    MIL.M_START, MIL.M_ASYNCHRONOUS, ProcessingFunctionPtr,
                    ctypes.byref(UserHookData))
    MIL.MdigProcess(MilDigitizer_1, MilGrabBufferList_1,
                    MilGrabBufferListSize_1, MIL.M_START, MIL.M_ASYNCHRONOUS,
                    ProcessingFunctionPtr_1, ctypes.byref(UserHookData_1))

    # Here the main() is free to perform other tasks while the processing is executing.
    # ---------------------------------------------------------------------------------
    #    for id in range(500):
    #       MIL.MbufExport(MIL.MIL_TEXT(".//test_image//F_FileName{i}.tif".format(i=id)), MIL.M_TIFF, MilImageDisp)
    # time.sleep(0.1/3)
    # Print a message and wait for a key press after a minimum number of frames.
    get_input("Press <Enter> to stop.                    \n\n")

    # Stop the processing.
    MIL.MdigProcess(MilDigitizer, MilGrabBufferList, MilGrabBufferListSize,
                    MIL.M_STOP, MIL.M_DEFAULT, ProcessingFunctionPtr,
                    ctypes.byref(UserHookData))
    MIL.MdigProcess(MilDigitizer_1, MilGrabBufferList_1,
                    MilGrabBufferListSize_1, MIL.M_STOP, MIL.M_DEFAULT,
                    ProcessingFunctionPtr_1, ctypes.byref(UserHookData_1))

    # Print statistics.
    ProcessFrameCount = MIL.MdigInquire(MilDigitizer,
                                        MIL.M_PROCESS_FRAME_COUNT, None)
    ProcessFrameRate = MIL.MdigInquire(MilDigitizer, MIL.M_PROCESS_FRAME_RATE,
                                       None)
    print(
        "\n{:d} frames grabbed at {:.1f} frames/sec ({:.1f} ms/frame)".format(
            ProcessFrameCount, ProcessFrameRate, 1000.0 / ProcessFrameRate))
    get_input("Press <Enter> to end.\n")

    # Free the grab buffers.
    for id in range(0, MilGrabBufferListSize):
        MIL.MbufFree(MilGrabBufferList[id])
    for id in range(0, MilGrabBufferListSize_1):
        MIL.MbufFree(MilGrabBufferList_1[id])

    # Release defaults.
    MIL.MbufFree(MilImageDisp_1)
    MIL.MbufFree(MilImageDisp_0)
    MIL.MbufFree(MilImageDisp)
    MIL.MdispFree(MilDisplay)
    MIL.MdispFree(MilDisplay_1)
    MIL.MdispFree(MilDisplay_2)
    MIL.MdigFree(MilDigitizer)
    MIL.MdigFree(MilDigitizer_1)
    MIL.MsysFree(MilSystem)
    MIL.MappFree(MilApplication)

    print("image processing...")
    # i=1
    # while True:
    #    try:

    #       imgFile1 = ".//test_image//2//Process_FileName{a}.tif".format(a=i)
    #       imgFile2 = ".//test_image//3//Process_FileName{a}.tif".format(a=i)

    #       img1 = cv2.imread(imgFile1, 1)
    #       img2 = cv2.imread(imgFile2, 1)

    #       addh = cv2.hconcat([img1, img2])

    #       # cv2.imshow("imgh", addh)

    #       cv2.imwrite(".//hcont//Process_FileName{a}.tif".format(a=i), addh)

    #       # cv2.waitKey(0)
    #       # cv2.destroyAllWindows()
    #       i = i+1
    #    except:
    #       break
    # print("finish")

    return