def getRigidBodies(label, working_dir): sseq = scipy.io.mmread(path + '/../' + working_dir + '/shape_' + label + '.mtx') nbp, R, r, Rc, rc, Rw, rw = frames(sseq) color, colorC, RB, RBC = {}, {}, {}, {} for i in range(int(nbp)): rrw, rrc, RRw, RRc = rw[i], rc[i], Rw[i], Rc[i] fuf = open(path + '/../' + working_dir + '/complete_' + label + '.txt', 'r') sus = fuf.read() fuf.close() base = sus[i] if base == 'A': baseC = 'T' if base == 'T': baseC = 'A' if base == 'C': baseC = 'G' if base == 'G': baseC = 'C' #### The variable with C is complementary strand,c i.e. color and colorC #### color[i], RB[i] = getRigidBodyConfig( rrw, RRw, base) # call the above function for both the watson colorC[i], RBC[i] = getRigidBodyConfig(rrc, RRc, baseC, 'C') # and crick strands return nbp, RBC, colorC, RB, color
def main(): fullbody_cascade = cv2.CascadeClassifier( '/Users/Aaron/Documents/College/Fourth_Year/Final_Year_Project/Datasets/body10/haarcascade_fullbody.xml' ) ap = argparse.ArgumentParser() ap.add_argument("-v", "--video", help="path to the video file") ap.add_argument("-a", "--min-area", type=int, default=500, help="minimum area size") args = vars(ap.parse_args()) if args.get("video", None) is None: camera = cv2.VideoCapture(0) # otherwise, we are reading from a video file else: print("[INFO] starting video file thread...") camera = myqueue(args["video"]).start() time.sleep(1.0) fps = frames().start() while camera.more(): frame = camera.read() frame = imutils.resize(frame, width=400) gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) cv2.putText(frame, "Queue Size: {}".format(camera.Q.qsize()), (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0, 255, 0), 2) fullbody = fullbody_cascade.detectMultiScale(gray, 1.3, 5) for (x, y, w, h) in fullbody: cv2.rectangle(frame, (x, y), (x + w, y + h), (255, 0, 0), 2) roi_gray = gray[y:y + h, x:x + w] roi_color = frame[y:y + h, x:x + w] peds_found = "Found " + str(len(fullbody)) + " Pedestrians" cv2.putText(frame, peds_found, (10, 55), cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0, 255, 0), 2) cv2.imshow("HaarCascade", frame) cv2.waitKey(1) fps.update() k = cv2.waitKey(27) & 0xff if k == 27: break fps.stop() print("[INFO] elapsed time: {:.2f}".format(fps.elapsed())) print("[INFO] approx. FPS: {:.2f}".format(fps.fps())) cv2.destroyAllWindows() camera.stop()
def cgDNA_MonteCarlo(*arg): #####Sample input: cgDNA_MonteCarlo(seq_label(s),nbr_samples,working_dir) n_arg = len(arg) nbr_samples = int(arg[n_arg - 2]) l_p, l_d = {}, {} for label in range(n_arg - 2): fuf = open( path + '/../' + arg[n_arg - 1] + '/complete_' + arg[label] + '.txt', 'r') sus = fuf.read() fuf.close() shape = scipy.io.mmread(path + '/../' + arg[n_arg - 1] + '/shape_' + arg[label] + '.mtx') stiff = scipy.io.mmread(path + '/../' + arg[n_arg - 1] + '/stiff_' + arg[label] + '.mtx') nbp = len(sus.strip()) dim = 12 * nbp - 6 MC = np.random.multivariate_normal(np.zeros(dim), np.eye(dim, dtype=int), nbr_samples) ttc = np.zeros((nbp, 1)) L = scipy.linalg.cholesky(stiff.todense()) #### if only one seq is provided, it will plot the different MC configurations#### if n_arg == 3: fig = plt.figure() ax = plt.axes(projection='3d') for jj in range(nbr_samples): x = np.linalg.solve(L, np.transpose(MC[jj])) + shape nbp, R, r, Rc, rc, Rw, rw = frames(x) XYZ = np.zeros((nbp, 3)) for k in range(nbp): XYZ[k] = r[k] ttc[k][0] = np.divide(R[k][2][2], nbr_samples) + ttc[k][0] if n_arg == 3: XYZ = np.transpose(XYZ) ax.plot3D(XYZ[0], XYZ[1], XYZ[2], 'blue') XYZ = np.transpose(XYZ) nbp, R, r, Rc, rc, Rw, rw = frames(shape) ttc_int = np.zeros((nbp, 1)) for k in range(nbp): XYZ[k] = r[k] ttc_int[k][0] = R[k][2][2] if n_arg == 3: XYZ = np.transpose(XYZ) ax.plot3D(XYZ[0], XYZ[1], XYZ[2], 'red') l_p[label], l_d[label], not_imp = Compute_pl(nbp, ttc, ttc_int) print("For ", arg[label], " l_p = ", l_p[label], " and l_d = ", l_d[label]) if n_arg == 3: plt.show() plt.savefig(path + 'Mon.png', format='png', dpi=1200)
pred.append((int(tp[0]), int(tp[1]))) def paint(tp, xA, yA, xB, yB): global frame, pred cv2.circle(frame, ((tp[0]), (tp[1])), 3, (0, 0, 255), -1) cv2.rectangle(frame, ((tp[0]) - ((xB - xA) / 2), (tp[1]) + (yB - yA) / 2), (((tp[0]) + ((xB - xA) / 2)), ((tp[1]) - (yB - yA) / 2)), (0, 0, 255), 2) # created a *threaded* video stream, allow the camera sensor to warmup, # and start the FPS counter print("[INFO] sampling THREADED frames from webcam...") vs = webcamThread(src=0).start() fps = frames().start() kalman = cv2.KalmanFilter(4, 2) kalman.measurementMatrix = np.array([[1, 0, 0, 0], [0, 1, 0, 0]], np.float32) kalman.transitionMatrix = np.array( [[1, 0, 1, 0], [0, 1, 0, 1], [0, 0, 1, 0], [0, 0, 0, 1]], np.float32) kalman.processNoiseCov = np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]], np.float32) * 0.03 hog = cv2.HOGDescriptor() hog.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector()) # loop over some frames...this time using the threaded stream while (True): # grab the frame from the threaded video stream and resize it # to have a maximum width of 600 pixels
def makepdb(*arg): n_arg = len(arg) for ii in range(n_arg - 1): fuf = open(path + '/../' + arg[n_arg - 1] + '/complete_' + arg[ii] + '.txt', 'r') sus = fuf.read() fuf.close() out = open(arg[ii] + '.pdb', 'w') shape = scipy.io.mmread(path + '/../' + arg[n_arg - 1] + '/shape_' + arg[ii] + '.mtx') nbp, R, r, Rc, rc, Rw, rw = frames(shape) ideal = np.loadtxt(path + '/../functions/' + 'ideal_bases.txt', skiprows=1, delimiter=',', usecols = (1,2,3)) atoms = np.loadtxt(path + '/../functions/' + 'ideal_bases.txt', skiprows=1, delimiter=',', usecols=(0), dtype=str) kk=0 for i in range(nbp): base = sus[i] cord = {} if base == 'A': for j in range(11): kk = kk + 1 cord[j] = rw[i] + np.matmul(Rw[i],np.transpose(ideal[j])) cord[j] = rw[i] + np.matmul(Rw[i],ideal[j]) out.write("ATOM "+str(kk)+" "+str(atoms[j])+" "+base+" "+str(i+1)+" "+' '.join(map(str, cord[j]))+"\n") if base == 'T': for j in range(10): kk = kk+1 cord[j] = rw[i] + np.matmul(Rw[i],np.transpose(ideal[j+11])) out.write("ATOM "+str(kk)+" "+str(atoms[j+11])+" "+base+" "+str(i+1)+" "+' '.join(map(str, cord[j]))+"\n") if base == 'G': for j in range(12): kk = kk+1 cord[j] = rw[i] + np.matmul(Rw[i],np.transpose(ideal[j+11+10])) out.write("ATOM "+str(kk)+" "+str(atoms[j+11+10])+" "+base+" "+str(i+1)+" "+' '.join(map(str, cord[j]))+"\n") if base == 'C': for j in range(9): kk = kk+1 cord[j] = rw[i] + np.matmul(Rw[i],np.transpose(ideal[j+11+10+12])) out.write("ATOM "+str(kk)+" "+str(atoms[j+11+10+12])+" "+base+" "+str(i+1)+" "+' '.join(map(str, cord[j]))+"\n") out.write('TER \n') F = [[1,0,0],[0,-1,0],[0,0,-1]] for i in range(nbp-1,-1,-1): base=comp(sus[i]) cord = {} if base == 'A': for j in range(11): kk = kk+1 cord[j] = rc[i] + np.matmul(Rc[i],np.matmul(F,np.transpose(ideal[j]))) out.write("ATOM "+str(kk)+" "+str(atoms[j])+" "+base+" "+str(2*nbp-i)+" "+' '.join(map(str, cord[j]))+"\n") if base == 'T': for j in range(10): kk = kk+1 cord[j] = rc[i] + np.matmul(Rc[i],np.matmul(F,np.transpose(ideal[j+11]))) out.write("ATOM "+str(kk)+" "+str(atoms[j+11])+" "+base+" "+str(2*nbp-i)+" "+' '.join(map(str, cord[j]))+"\n") if base == 'G': for j in range(12): kk = kk+1 cord[j] = rc[i] + np.matmul(Rc[i],np.matmul(F,np.transpose(ideal[j+11+10]))) out.write("ATOM "+str(kk)+" "+str(atoms[j+11+10])+" "+base+" "+str(2*nbp-i)+" "+' '.join(map(str, cord[j]))+"\n") if base == 'C': for j in range(9): kk = kk+1 cord[j] = rc[i] + np.matmul(Rc[i],np.matmul(F,np.transpose(ideal[j+11+10+12]))) out.write("ATOM "+str(kk)+" "+str(atoms[j+11+10+12])+" "+base+" "+str(2*nbp-i)+" "+' '.join(map(str, cord[j]))+"\n") out.close() return