diff --git a/MatPlotLib/aglomerat.py b/MatPlotLib/aglomerat.py new file mode 100644 index 0000000..0047aaf --- /dev/null +++ b/MatPlotLib/aglomerat.py @@ -0,0 +1,107 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Fri Dec 15 23:36:50 2017 + +@author: fh + +Simulation d'aglomération de particules +""" +def matrix_rand(L,C,d=0.10): + from numpy import zeros + from time import sleep + from random import random as rand + M=zeros([L,C],dtype=bool) + for i in range(L): + for j in range(C): + r=rand() + v=rabs(Fx) and Fy>0 and (not M[Nl,c ]):#Au nord. + #Centre->Nord. + M[l,c],M[Nl,c ]=False,True + elif abs(Fy)>abs(Fx) and Fy<0 and (not M[Sl,c ]):#Au sud. + #Centre->Sud. + M[l,c],M[Sl,c ]=False,True + elif abs(Fx)>abs(Fy) and Fx>0 and (not M[l ,Ec]):#A l'est. + #Centre->Est. + M[l,c],M[l ,Ec]=False,True + elif abs(Fx)>abs(Fy) and Fx<0 and (not M[l ,Oc]):#A l'ouest. + #Centre->Ouest. + M[l,c],M[l ,Oc]=False,True + return M +def aglo_test(): + M=matrix_rand(20,20) + M1=M + for t in range(1): + M1=aglo(M1) + print(M*1) + print(M1*1) + print("Sommes :",M.sum()," et ",M1.sum(),".") + print("M=M1 :\n",(M==M1)*1) + print("Densité : ",M.sum()/M.size) +from matplotlib.pyplot import imshow,figure,pause,title +figure("Graphe") +for t in range(31): + M=matrix_rand(200,200,0.8) + imshow(M,cmap='gray',interpolation='nearest') + ttr="Itération :{:d}".format(t) + ttr+="\nDensité : {:03.1f}%".format(M.sum()*100/M.size) + title(ttr) + pause(0.99) \ No newline at end of file diff --git a/MatPlotLib/masque_gaussien.py b/MatPlotLib/masque_gaussien.py new file mode 100644 index 0000000..849cff6 --- /dev/null +++ b/MatPlotLib/masque_gaussien.py @@ -0,0 +1,16 @@ +#!/env/bin python +# -*- coding: utf-8 -*- +""" +Éditeur de Spyder + +Script pour faire une nuance de gris sinusoïdeale. +""" +from numpy import array,linspace,sin,ones,pi +import matplotlib.pyplot as plt +import matplotlib.colors as clr +image=ones([1000,1000]) +for x in range(1,1000): + image[x][:]=sin(x*2*pi/100)*ones([1000]) +plt.figure() +plt.imshow(image,cmap='gray') +plt.title("Sinusoïde de NdG") \ No newline at end of file diff --git a/OpenCV/videoHistogramme.py b/OpenCV/videoHistogramme.py new file mode 100644 index 0000000..ad81ea1 --- /dev/null +++ b/OpenCV/videoHistogramme.py @@ -0,0 +1,24 @@ +#!/bin/env python3 +# *-* utf-8 *-* +import numpy as np +import matplotlib.pyplot as plt +import cv2 +import time +# Code principal. +cap = cv2.VideoCapture(0) +ret, frame = cap.read() +[xl, yl, cl] = np.shape(frame) +red = np.ones([xl, yl, cl]) +green = np.ones([xl, yl, cl]) +blue = np.ones([xl, yl, cl]) +while(True): + ret, frame = cap.read() + gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) + hist = cv2.calcHist([gray],[0],None,[256],[0,256]) + plt.plot(np.linspace(0,255,256),hist.T[0]) + plt.imshow('video', hist) + if (cv2.waitKey(1) & 0xFF == ord('q')) : + break + time.sleep(1) +cap.release() +cv2.destroyAllWindows() diff --git a/PyQT/bidule.py b/PyQT/bidule.py new file mode 100644 index 0000000..7983bbc --- /dev/null +++ b/PyQT/bidule.py @@ -0,0 +1,86 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Thu Jul 6 14:02:21 2017 + +@author: fh +""" +import numpy as np +import sys +from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QVBoxLayout, QGridLayout, QLabel, QLineEdit, QCheckBox, QGroupBox +from PyQt5.QtCore import Qt +from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas +from matplotlib.figure import Figure +import matplotlib.pyplot as plt +class Bidule(QWidget): + def __init__(self): + QWidget.__init__(self) + self.setWindowTitle("Le bidule")#Titre de boîte + self.resize(250,250)#Taille de boîte + self.boite=QVBoxLayout()#Boîte verticale + self.fig = Figure()#Créer une figure. + self.axes1 = self.fig.add_subplot(121)#Figure1 + self.axes2=self.fig.add_subplot(122)#Figure2 + self.x1=np.linspace(-np.pi,np.pi) + self.x2=np.linspace(1,100) + self.y1=np.cos(self.x1)**2-np.sin(self.x1) + self.y2=np.exp(-self.x2**2) + self.line1,=self.axes1.plot(self.x1,self.y1) + self.line2,=self.axes2.plot(self.x2,self.y2) + self.canvas=FigureCanvas(self.fig)#Toile portant la figure de Matplotlib. + self.layout.addWidget(self.canvas) + self.setLayout(self.boite)#Placer boîte + self.soustitre=QLabel("Boîte à bouttons")#Sous-titre de sous-boîte + self.soustitre.setMaximumSize(200,15)#Taille de sous-titre + self.boite.addWidget(self.soustitre)#Placer sous-titre + self.sousboite=QGridLayout()#Sous-boîte en matrice pour les bouttons + self.boite.addLayout(self.sousboite)#Placer sous-boîte + self.bouttons=[]#Liste des bouttons vide + self.numeros=[]#Liste des numéros vide + self.appuyer=[] + for l in range(5): + self.bouttons+=[[]]#Lignes de bouttons + self.numeros+=[[]]#Lignes de numéros + self.appuyer+=[[]] + for c in range(5): + self.bouttons[l]+=[QPushButton()]#Colonnes de bouttons + self.numeros[l]+=["{}{}".format(l,c)]#Colonnes de numéros + self.appuyer[l]+=[np.sin] + self.bouttons[l][c].setMaximumSize(30,30)#Taille des bouttons + self.bouttons[l][c].setText(self.numeros[l][c])#Numéros des bouttons + self.sousboite.addWidget(self.bouttons[l][c],l,c)#Placer tous les bouttons + def appui(): + if self.bouttons[l][c].clicked!=QPushButton.clicked: + if self.numeros[l][c] == self.bouttons[l][c].text(): + self.bouttons[l][c].setText("["+self.numeros[l][c]+"]") + else: + self.bouttons[l][c].setText(self.numeros[l][c]) + self.appuyer[l][c]=appui + self.bouttons[l][c].clicked.connect(self.appuyer[l][c])#Connection entre bouttons et "appuyer" + self.show()#Afficher. +''' + def appuyer(self): + n=self.numeros + t=[] + for l in range(len(self.bouttons)): + t+=[[]] + for c in range(len(self.bouttons[0])): + t[l]+=[self.bouttons[l][c].text()] + for l in range(len(self.bouttons)): + for c in range(len(self.bouttons[0])): + if self.bouttons[l][c].clicked==QPushButton.clicked: + if n[l][c]==t[l][c]: + self.bouttons[l][c].setText("["+n[l][c]+"]") + else: + self.bouttons[l][c].setText(n[l][c]) +''' + + +def ouvrirBidule(): + app = QApplication.instance() + if not app: + app = QApplication(sys.argv) + objet = Bidule() + objet.show() + app.exec_() +ouvrirBidule() \ No newline at end of file