def main(): print("Press 't' Key to take a Test Screenshot") print("The values of the screenshot should be shown in the terminal") #set_items_for_run() set_test_items_for_run() run_open_cv() my_cv.test_read_in(CONST_Initial_Stats) create_item(CONST_Initial_Stats)
def Video2(openpath, savepath="output.avi", roi=None): cap = cv2.VideoCapture(openpath) if cap.isOpened(): print("Video Opened") else: print("Video Not Opened") print("Program Abort") exit() fps = cap.get(cv2.CAP_PROP_FPS) width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) fourcc = int(cap.get(cv2.CAP_PROP_FOURCC)) out = cv2.VideoWriter(savepath, fourcc, fps, (width, height), True) cv2.namedWindow("Input", cv2.WINDOW_GUI_EXPANDED) cv2.namedWindow("Output", cv2.WINDOW_GUI_EXPANDED) import OpenCV while cap.isOpened(): # Capture frame-by-frame ret, frame = cap.read() if ret: # Our operations on the frame come here output = OpenCV.imageProcessing(frame, roi) # Write frame-by-frame out.write(output) # Display the resulting frame cv2.imshow("Input", frame) cv2.imshow("Output", output) else: break # waitKey(int(1000.0/fps)) for matching fps of video if cv2.waitKey(int(1000.0 / fps)) & 0xFF == ord('q'): break # When everything done, release the capture cap.release() out.release() cv2.destroyAllWindows() return
import client import OpenCV color = client.client_socket() print("The Choosen color was ", color) print("Press Esc to quit...") OpenCV.img_process(color)
thread = threading.Thread(target=self.grabImages, args=[id]) self.threads.append(thread) self.threads[-1].start() def waitAll(self): i = 0 for thread in self.threads: thread.join() i += 1 print("finish:" + std(i)) if __name__ == "__main__": app = QApplication(sys.argv) count = ocv.OpenCV().getDeviceCount() view = mw.MainWindow(count) view.show() model = [] for i in range(count): obcv = ocv.OpenCV() model.append(obcv) controller = Controller(model, view) for i in range(count): controller.start(i)
import OpenCV OpenCV.calculate_disp(1, 100)
# Copyright (c) 2014, Adam J. Rossi. All rights reserved. See README for licensing details. import sys, os sys.path.append(os.path.abspath(".")) import Chain import Sources, OpenCV imagePath = os.path.abspath("../Datasets/ET") imageSource = Sources.ImageSource(imagePath, "jpg") fd = OpenCV.FeatureDetector(imageSource, forceRun=True) fm = OpenCV.FeatureMatcher(fd, "BruteForce", os.path.join(imagePath, "matches.txt"), forceRun=True) print(Chain.Render(fm, 'openCV.txt'))
class Game: """ Container class for all game relevant information. This class stores all informations regarding the current state of the game like the individual fields or changes that occurred (i.e. after clicking a square). """ _open_cv = OpenCV() # The initial square locations at the beginning of the game. _initial_squares = [] # The width of a single square on the game field. _initial_square_width = 0 # The current field. current_field_info = None # The fields whose state differed during the comparion. changed_fields = [] is_finished = False def __init__(self): self._open_cv = OpenCV() def update_field_dimensions(self, window): """ Function for udpating the game's field dimesions like number of squares, rows, columns and the individual size of each square. """ l.debug("Updating field dimensions...") image = window.get_window_image() self._initial_squares = self._open_cv.get_field_information(image) distances = [] for row in self._initial_squares: prev_next_tuples = zip(row[:-1], row[1:]) distances += list(map(lambda tuple: tuple[1].center_coordinates[0] - tuple[0].center_coordinates[0], prev_next_tuples)) # Minimum since the distance is compared in such a way that the program # tests if a square can be inserted based on the distance between two # coordinates. self._initial_square_width = min(distances) def update(self, window): """ Function for updating the current state of the game. The field as well as any other relevenat information (changes, etc.) are gathered here. """ # Update the field information using OpenCV. l.debug("Getting window image...") image = window.get_window_image() l.debug("Getting field information...") self.is_finished = self._open_cv.is_finished(image) if not self.is_finished: new_field_info = self._open_cv.get_field_information(image) self.fill_empty_spaces(new_field_info) self.compare_and_update_field_info(new_field_info) def fill_empty_spaces(self, field_info): l.debug("Filling empty spaces with zeroes...") # Fill any empty spots with the previously extracted coordinates such that # the result is the complete game field. for row_index in range(0, len(self._initial_squares)): for column_index in range(0, len(self._initial_squares[row_index])): stored = self._initial_squares[row_index][column_index] checked_stored = Square(stored.center_coordinates, 0, False) # Empty fields at the ends must be added manually. if column_index >= len(field_info[row_index]): field_info[row_index].append(checked_stored) else: new = field_info[row_index][column_index] difference_x = abs(new.center_coordinates[0] - stored.center_coordinates[0]) # Distance greater than the previously calculated distance means # that an entry is missing here. if difference_x >= self._initial_square_width: field_info[row_index].insert(column_index, checked_stored) # Crude display of the result. l.debug("Filling results: {} rows with {} columns".format(len(field_info), list(map(lambda x: len(x), field_info)))) for row in field_info: line = "" for column in row: if column.is_unchecked: line += "?" else: line += str(column.value) l.debug(line) def compare_and_update_field_info(self, field_info): """ Function for updating the collection of fields that changed compared to the stored ones. """ l.debug("Checking for differences...") # Previous changes must be reset. self.changed_fields.clear() change_occurred = False # First update cycle. if self.current_field_info is None: self.current_field_info = field_info change_occurred = True l.info("Field state initialized.") # Each square must be compared in order to determine whether # a change occurred. Checking the field representing the checked # property is enough since the values of the squares do not change. else: # Row and column count match the entire game. for row_index in range(0, len(self.current_field_info)): for column_index in range(0, len(self.current_field_info[row_index])): old_square = self.current_field_info[row_index][column_index] new_square = field_info[row_index][column_index] if old_square.is_unchecked and not new_square.is_unchecked: l.debug("Field state differs at [{}][{}]. value={}".format(row_index, column_index, new_square.value)) # Keep track of the changes on the field. square_change = SquareChange(old_square, new_square, row_index, column_index) self.changed_fields.append(square_change) change_occurred = True # Update the field state such that the new one can be # retrieved. self.current_field_info = field_info if change_occurred: l.info("Field state differs.") return change_occurred
def __init__(self): self._open_cv = OpenCV()
def InitUI(self): self.MainInterface = Interface.Interface(self) self.MainModel = Robot_Model.Robot_Model(self) self.OpenCV = OpenCV.OpenCV(self) self.FeatureDict = {} self.CurrentFeature = None self.XPID = PID.PID(0.4, 0.015, 0.15) #PID controller for pan self.XPID.setPoint(self.OpenCV.CamCentreX) self.YPID = PID.PID(0.4, 0.015, 0.15) #PID controller for tilt self.YPID.setPoint(self.OpenCV.CamCentreY) self.AddFeature = wx.Button(self, label="Add Feature") self.AddFeature.Bind(wx.EVT_LEFT_DOWN, self.OnAddFeature) self.RemoveFeature = wx.Button(self, label="Remove Feature") self.RemoveFeature.Bind(wx.EVT_LEFT_DOWN, self.OnRemoveFeature) self.FeatName = wx.TextCtrl (self) self.Save = wx.Button(self, label="Save") self.Save.Bind(wx.EVT_LEFT_DOWN, self.SaveFeatures) self.Load = wx.Button(self, label="Load") self.Load.Bind(wx.EVT_LEFT_DOWN, self.LoadFeatures) self.FeatureCtrl = wx.ListCtrl(self, size=(-1,100), style=wx.LC_REPORT |wx.BORDER_SUNKEN) self.FeatureCtrl.InsertColumn(0, 'Name') self.FeatureCtrl.InsertColumn(1, 'Type') self.FeatureCtrl.Bind(wx.EVT_LIST_ITEM_SELECTED, self.FeatureChanged) self.XLabel = wx.StaticText(self, label="X:") self.XValue = wx.TextCtrl(self, size=(80, -1)) self.YLabel = wx.StaticText(self, label="Y:") self.YValue = wx.TextCtrl(self, size=(80, -1)) self.ZLabel = wx.StaticText(self, label="Z:") self.ZValue = wx.TextCtrl(self, size=(80, -1)) self.PanLabel = wx.StaticText(self, label="Pan:") self.PanValue = wx.TextCtrl(self, size=(80, -1)) self.TiltLabel = wx.StaticText(self, label="Tilt:") self.TiltValue = wx.TextCtrl(self, size=(80, -1)) Options = ['None','Detect','Track'] self.MatchChoice = wx.Choice(self, choices = Options) self.MatchChoice.SetSelection(0) self.hsizer = wx.BoxSizer(wx.HORIZONTAL) self.hsizer2 = wx.BoxSizer(wx.HORIZONTAL) self.hsizer3 = wx.BoxSizer(wx.HORIZONTAL) self.hsizer4 = wx.BoxSizer(wx.HORIZONTAL) self.hsizer5 = wx.BoxSizer(wx.HORIZONTAL) self.hsizer6 = wx.BoxSizer(wx.HORIZONTAL) self.vsizer = wx.BoxSizer(wx.VERTICAL) self.hsizer.Add(self.MainInterface, wx.ALL, border = 5) self.hsizer.Add(self.OpenCV, wx.ALL, border = 5) self.hsizer.Add(self.MainModel, wx.ALL, border = 5) self.hsizer2.Add(self.AddFeature) self.hsizer2.Add(self.RemoveFeature) self.hsizer2.Add(self.FeatName) self.hsizer3.Add(self.Save) self.hsizer3.Add(self.Load) self.hsizer4.Add(self.XLabel) self.hsizer4.Add(self.XValue) self.hsizer4.Add(self.YLabel) self.hsizer4.Add(self.YValue) self.hsizer4.Add(self.ZLabel) self.hsizer4.Add(self.ZValue) self.hsizer5.Add(self.FeatureCtrl) self.hsizer5.Add(self.MatchChoice) self.hsizer6.Add(self.PanLabel) self.hsizer6.Add(self.PanValue) self.hsizer6.Add(self.TiltLabel) self.hsizer6.Add(self.TiltValue) self.vsizer.Add(self.hsizer) self.vsizer.Add(self.hsizer2) self.vsizer.Add(self.hsizer3) self.vsizer.Add(self.hsizer5) self.vsizer.Add(self.hsizer4) self.vsizer.Add(self.hsizer6) self.SetSizer(self.vsizer) self.vsizer.SetSizeHints(self) self.SetTitle('Big Face Robotics - Robot Head Controller') self.Centre() self.timer = wx.Timer(self) self.Bind(wx.EVT_TIMER, self.OnTimer) self.timer.Start(1000/20) # timer interval
# Copyright (c) 2014, Adam J. Rossi. All rights reserved. See README for licensing details. import sys, os sys.path.append(os.path.abspath(".")) import Chain # Chain must be imported first, requirement of registry import Sources, FeatureExtraction, FeatureMatch, BundleAdjustment, Cluster, OpenCV # path to images / PMVS imagePath = os.path.abspath("../Datasets/ET") pmvsPath = os.path.join(imagePath, "pmvs") # build chain imageSource = Sources.ImageSource(imagePath, "jpg") sift = OpenCV.FeatureDetector(imageSource) keyMatch = OpenCV.FeatureMatcher(sift) bundler = BundleAdjustment.Bundler([keyMatch, imageSource]) radialUndistort = Cluster.RadialUndistort([bundler, imageSource]) prepCmvsPmvs = Cluster.PrepCmvsPmvs(radialUndistort, pmvsPath) cmvs = Cluster.CMVS(prepCmvsPmvs) pmvs = Cluster.PMVS(cmvs) # render chain print Chain.Render(pmvs, "sfmOpenCV.txt")
import OpenCV OpenCV.calculate_disp(1,100)