def exposed_load_microscope(self, config_path=default["mm"]["cfg_file"]): """initialize MMCore for the given micro-manager config file""" config_abspath = os.path.abspath(config_path) # store the current working dir, so that we can change it back after # device adapters are pointed to the micromanager directory # changing the working directory to mm_dir is necessary for pymmcore # to find the device adapters (stored in mm_dir) correctly working_dir = os.getcwd() if os.name == 'nt': # check if windows # ah! the microscope computer mm_dir = default["mm"]["win_path"] elif os.name == "posix": # the dev's linux computer mm_dir = default["mm"]["linux_path"] os.chdir(mm_dir) mmc = pymmcore.CMMCore() mmc.setDeviceAdapterSearchPaths([mm_dir]) mmc.loadSystemConfiguration(config_abspath) os.chdir(working_dir) self.exposed_mmc = mmc return mmc
def show_frame(self): # _, frame = self.cap.read() # frame = cv2.flip(frame, 1) # cv2image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGBA) # img = Image.fromarray(cv2image) # imgtk = ImageTk.PhotoImage(image=img) # self.lmain.imgtk = imgtk # self.lmain.configure(image=imgtk) # self.lmain.after(10, self.show_frame) mmc = pymmcore.CMMCore() print('-----setup cam-----') mm_dir = 'C:/Program Files/Micro-Manager-2.0gamma/' mmc.setDeviceAdapterSearchPaths([mm_dir]) print(mmc.getVersionInfo()) print(mmc.getAPIVersionInfo()) use_YOLO = False my_yolo = YOLO() # start yolo session print('-----load cam-----') # print(os.path.join(mm_dir, 'MMConfig_1.cfg')) mmc.loadSystemConfiguration(mm_dir + 'MMConfig_QCam.cfg') mmc.setExposure(200) cv2.namedWindow('live', cv2.WINDOW_AUTOSIZE) mmc.startContinuousSequenceAcquisition(1) while True: if mmc.getRemainingImageCount() > 0: start = timer() frame = mmc.popNextImage() # Run detection if use_YOLO: alter = contrastStretch(frame, min_range, max_range) image = Image.fromarray(np.uint8(alter)) output = detect_img(my_yolo, image) output = np.array(output) cv2.imshow('live', output) else: cv2.imshow('live', frame) end = timer() save_time = end - start if cv2.waitKey(1) & 0xFF == ord( 'q' ): # This break key is critical, otherwise the live image does not load break
# N = 1024 # for m in range(0,M): # for n in range(0,N): # if minI < iI[m,n] < maxI: # iI[m,n] = iI[m,n] # elif iI[m,n] < minI: # iI[m,n] = 0 # elif iI[m,n] > maxI: # iI[m,n] = 255 # if iI < minI: # iO = 0 # if iI > maxI: # iO = 255 return iO mmc = pymmcore.CMMCore() print('-----setup cam-----') mm_dir = 'C:/Program Files/Micro-Manager-2.0gamma/' mmc.setDeviceAdapterSearchPaths([mm_dir]) print(mmc.getVersionInfo()) print(mmc.getAPIVersionInfo()) use_YOLO = True my_yolo = YOLO() # start yolo session print('-----load cam-----') # print(os.path.join(mm_dir, 'MMConfig_1.cfg')) mmc.loadSystemConfiguration(mm_dir + 'MMConfig_QCam.cfg') mmc.setExposure(200) mmc.snapImage() im1 = mmc.getImage()
import pymmcore import configparser import os.path # # At the moment, the only test is that our version number is correct # script_dir = os.path.dirname(os.path.realpath(__file__)) setup_cfg = os.path.join(os.path.dirname(script_dir), 'setup.cfg') config = configparser.ConfigParser() config.read(setup_cfg) pymmcore_version = config['metadata']['version'].split('.') print("Version: {}".format(pymmcore_version)) # getVersionInfo() returns a string like "MMCore version x.y.z" mmcore_version = pymmcore.CMMCore().getVersionInfo().split()[-1].split('.') print("MMCore version: {}".format(mmcore_version)) for i in range(3): if pymmcore_version[i] != mmcore_version[i]: raise AssertionError('Version mismatch between pymmcore and MMCore')