def read_webcam_feed(detectorsN, deviceID): cap = cv.VideoCapture(deviceID) while True: ret, frame = cap.read() message = (Atom("frame"), j, frame) if ret else Atom("error") # Send the frame to a random Erlang detector process receiver = randint(1, detectorsN) erlang.call(Atom("gen_server"), Atom("cast"), [(Atom("global"), receiver), message])
def detect_face(frame, fid, worker): face_cascade = cv.CascadeClassifier("/home/andreea/Documents/catkin_ws/src/rosorbitcamera/src/HaarClassifiers/haarcascade_frontalface_1.xml") image = np.array(frame, dtype="uint8") best_face = [] faces = face_cascade.detectMultiScale(image, scaleFactor=1.1, minNeighbors=6, minSize=(50, 50), flags=cv.cv.CV_HAAR_SCALE_IMAGE) if faces != () and faces.size > 0: # OpenCv strangely returns empty tuples occasionally, so check for that best_face = max(faces, key=lambda item:item[2]) if best_face!=[]: best_face = best_face.tolist() erlang.call(Atom("gen_server"), Atom("cast"), [(Atom("global"),Atom("aggregator_server")), (Atom("face"),fid, worker, best_face)])
def read_folder_feed(detectorsN, deviceID): pics={} j = 0 for filename in natural_sort(glob.glob('/home/andreea/Pictures/Webcam/Input/*.jpg')): pics[j]=cv.imread(filename) j+=1 j=0 for key in pics.keys(): frame = cv.cvtColor(pics[key], cv.COLOR_BGR2GRAY) message = (Atom("frame"),j+1,frame) time.sleep(0.3) receiver = randint(1,detectorsN) erlang.call(Atom("gen_server"), Atom("cast"), [(Atom("global"),receiver), message])
def pids_more(num): pidlist = [] for x in range(0,num): pidlist.append(call(Atom("erlang"), Atom("self"), [])) print "You just spawned " + str(num) + " processes in BEAM VM." print "Here they are!" return pidlist
def read_folder_feed(detectorsN, deviceID): pics = {} j = 0 for filename in natural_sort( glob.glob('/home/andreea/Pictures/Webcam/Input/*.jpg')): pics[j] = cv.imread(filename) j += 1 j = 0 for key in pics.keys(): frame = cv.cvtColor(pics[key], cv.COLOR_BGR2GRAY) message = (Atom("frame"), j + 1, frame) time.sleep(0.3) receiver = randint(1, detectorsN) erlang.call(Atom("gen_server"), Atom("cast"), [(Atom("global"), receiver), message])
def sendMoveResult(): print("Sending move result") res = "success" board = [[('a', 1, 1, 1), ('b', 2, 2, 2)], [('c', 3, 3, 3), ('d', 4, 4, 4)]] scores = (10, 15, 20, 30) tile_old_new = ([('e', 5, 5, 5)], [()]) tupac = (res, board, scores, tile_old_new) res = call(Atom("scrabble"), Atom("sendMoveResult"), [tupac]) print(res) print("Finished sending thing")
def render_layout(path): """Render a layout from dasherl erlang side.""" # simply call to erlang module and ask for app rendering that path layout = call(Atom("dasherl_router"), Atom("render"), [path]) # maybe route doesnt exists so validate response if layout == 'no_such_layout': return None else: return layout
def __init__(self, **kwargs): options = self.parse_options(kwargs) # TODO: Handle 'node' option with 'rpc' module result = erlang.call(Atom("python"), Atom("start"), options) if type(result) != tuple or len(result) != 2: # TODO: Fix exception raise Exception(result) if result[0] is not Atom("ok"): # TODO: Fix exception raise Exception(result[1]) self.pid = result[1]
def detect_face(frame, fid, worker): face_cascade = cv.CascadeClassifier( "/home/andreea/Documents/catkin_ws/src/rosorbitcamera/src/HaarClassifiers/haarcascade_frontalface_1.xml" ) image = np.array(frame, dtype="uint8") best_face = [] faces = face_cascade.detectMultiScale(image, scaleFactor=1.1, minNeighbors=6, minSize=(50, 50), flags=cv.cv.CV_HAAR_SCALE_IMAGE) if faces != ( ) and faces.size > 0: # OpenCv strangely returns empty tuples occasionally, so check for that best_face = max(faces, key=lambda item: item[2]) if best_face != []: best_face = best_face.tolist() erlang.call(Atom("gen_server"), Atom("cast"), [(Atom("global"), Atom("aggregator_server")), (Atom("face"), fid, worker, best_face)])
def on_serial(SER): p = re.compile('<.*>') while True: try: packet = str(SER.readline()) except: call(Atom("postman_service"), Atom("stop"), []) result = p.search(packet) if result: #print("\t<--: {}".format(result.group(0))) rf_packet = packet_decode(result.group(0)) print("<-- {} encoded:{}\n".format(rf_packet, result.group(0))) if rf_packet : message = (rf_packet.hop_count, rf_packet.cmd, rf_packet.next_hop, rf_packet.destination, rf_packet.source, rf_packet.data) #call(Atom("mpn_controller_service"), Atom("response_handler"), [message]) for subscriber in SUBSCRIBERS: cast(subscriber, message)
def callErl(): print("msgErl") print(serverPID) tileArray = [('a', 1, 1, 1), ('b', 2, 2, 2)] direction = 'r' start_pos = (0, 0) tupac = (tileArray, direction, start_pos) res = call(Atom("scrabble"), Atom("send_messages"), [serverPID, tupac]) #res = call(Atom("scrabble"), Atom("send_messages"), [serverPID]) #res = call(Atom("erlang"), Atom("self"), []) print(res)
def response(key, args): """Process the callback to erlang side and wait for response.""" try: response = call(Atom("dasherl_binding"), Atom("callback"), [key, args]) # maybe response breaks! if response == 'error_in_response': raise dash.exceptions.PreventUpdate else: # parse response in order to check if comes a figure in it response = _parse_response(response) return response except BaseException, ex: print(str(ex)) raise dash.exceptions.PreventUpdate
def get_board(self): """ get_board(self):: Internal function to request board from erlang client Outputs: An internal call to print the received board. Also method of passing death request from erlang server """ board = call(Atom("just_snek_things"), Atom("get_board"), \ [self.server]) if board == Atom("die"): time.sleep(1) self.root.destroy() sys.exit(0) self.print_board(board) self.root.after(200, self.get_board)
def send(conn, data): erlang.call(Atom(b'shuwa_exproto'), Atom(b'send'), [conn, data]) return
def recurse(python, n): if n <= 0: return Atom("done") return erlang.call(Atom("python2_tests"), Atom("recurse"), [python, n - 1])
def send_direct_message(self, msg, user): call(Atom(b"Elixir.SlackBot"), Atom(b"send_direct_message"), [msg.encode('utf-8'), user.encode('utf-8')])
def rev_call(pid, r): erlang.call(Atom(b'erlport_SUITE'), Atom(b'handle_call'), [pid, r]) return
def dbGet(key): return call(API, Atom("db_get"), [PREFIX + key])
def publish(self, connection: Connection, message: Message): erlang.call(Atom(b'emqx_exproto'), Atom(b'publish'), [connection.pid, Message.to_erlang_data_type(message)])
def terminate(self, connection: Connection): erlang.call(Atom(b'emqx_exproto'), Atom(b'close'), [connection.pid])
def handler(message): erlang.call(Atom("python2_tests"), Atom("test_callback"), [(Atom("message"), message)])
def btn_clicked(event=None): ennteredtxt = self.entry.get() self.append(ennteredtxt) self.entry.delete(0, END) erlang.call(Atom(b"pe_client"), Atom(b"send"),[self.pid,ennteredtxt])
def send(self, connection: Connection, data: bytes): erlang.call(Atom(b'emqx_exproto'), Atom(b'send'), [connection.pid, data])
def pids(): Pid1 = call(Atom("erlang"), Atom("self"), []) Pid2 = call(Atom("erlang"), Atom("self"), []) return [Pid1, Pid2]
def register(self, connection: Connection, client_info: ClientInfo): erlang.call( Atom(b'emqx_exproto'), Atom(b'register'), [connection.pid, client_info.to_erlang_data_type()])
def dbSet(key, value): return call(API, Atom("db_set"), [PREFIX + key, value])
def subscribe(self, connection: Connection, topic: str, qos: int): erlang.call(Atom(b'emqx_exproto'), Atom(b'subscribe'), [connection.pid, bytes(topic), qos])
def register(conn, clientinfo): erlang.call(Atom(b'shuwa_exproto'), Atom(b'register'), [conn, clientinfo]) return
def send_message(dest_pid, message): retvalue = call(Atom("scrabble"), Atom("send_messages"), [dest_pid, message])
def subscribe(conn, topic, qos): erlang.call(Atom(b'shuwa_exproto'), Atom(b'subscribe'), [conn, topic, qos]) return
def send_message(self, msg, channel): call(Atom(b"Elixir.SlackBot"), Atom(b"send_message"), [msg.encode('utf-8'), channel.encode('utf-8')])
def getAvailablePrivPlugins(): """ "Callback" to Erlang to get available plugins for MUC. """ return call(API, Atom("available_plugins"), [])
def call(self, module, function, args): # TODO: Check all arguments # TODO: Reraise Python related exceptions return erlang.call(Atom("python"), Atom("call"), [self.pid, module, function, args])
def switch(n): result = 0 for i in range(n): _, result = erlang.call(Atom("python2_tests"), Atom("test_callback"), [(result, i)]) return n
def stop(self): # TODO: Check result erlang.call(Atom("python"), Atom("stop"), [self.pid])
def close(conn): erlang.call(Atom(b'shuwa_exproto'), Atom(b'close'), [conn]) return
def publish(conn, message): erlang.call(Atom(b'shuwa_exproto'), Atom(b'publish'), [conn, message]) return
def send_new_urls(urls): mod = "Elixir.Downloader.Server" erlang.call(mod, "download_urls", [urls])
def unsubscribe(conn, topic): erlang.call(Atom(b'shuwa_exproto'), Atom(b'subscribe'), [conn, topic]) return
def getAvailablePlugins(muc): """ "Callback" to Erlang to get available plugins for MUC. """ return call(Atom("urusai_erlapi"), Atom("available_plugins"), [muc])