我有这个Python代码,不知怎的,我得到错误信息:
Run Code Online (Sandbox Code Playgroud)File "/app/identidock.py", line 13, in mainpage if request.method == 'POST': NameError: name 'request' is not defined
但我真的找不到我的错误.有人可以帮我吗?
from flask import Flask, Response
import requests
import hashlib
app = Flask(__name__)
salt = "UNIQUE_SALT"
default_name = 'test'
@app.route('/', methods=['GET', 'POST'])
def mainpage():
name = default_name
if request.method == 'POST':
name = request.form['name']
salted_name = salt + name
name_hash = hashlib.sha256(salted_name.encode()).hexdigest()
header = '<html><head><title>Identidock</title></head><body>'
body = '''<form method="POST">
Hallo <input type="text" name="name" value="{0}">
<input type="submit" value="Abschicken">
</form>
<p> Du siehst aus wie …Run Code Online (Sandbox Code Playgroud) 我试图循环包含像素数据的nparray.我想对每个像素值执行均衡,并将它们显示为直方图.
我已经通过以下方式实现了我的目标:
def stratch_contrast(img):
hist,bins = np.histogram(img.flatten(),256,[0,256])
cdf = hist.cumsum()
cdf_normalized = cdf * hist.max()/ cdf.max()
cdf_m = np.ma.masked_equal(cdf,0)
cdf_m = (cdf_m - cdf_m.min())*255/(cdf_m.max()-cdf_m.min())
cdf = np.ma.filled(cdf_m,0).astype('uint8')
img = cdf[img]
plt.hist(img.flatten(),256,[0,256], color = 'black')
plt.xlim([0,256])
plt.legend(('cdf','histogram'), loc = 'upper left')
plt.show()
img = cv2.imread(name,0)
equ = cv2.equalizeHist(img)
res = np.hstack((img,equ)) #stacking images side-by-side
cv2.imwrite('res.png',res)
return
Run Code Online (Sandbox Code Playgroud)
但我真的希望这样做而不使用预定义函数进行学习.
所以我试着跟随:
def stratch_contrast(img, darkestValue, whitestValue):
newImgPixelList = []
h = img.shape[0] #number of pixels in the hight
w = img.shape[1] #number of piexels in …Run Code Online (Sandbox Code Playgroud) 有人可以告诉我在哪里以及如何关闭这里的连接吗?我是否必须在 Connection 类或 Controller 类中关闭 Connection?我已经尝试在连接类中的方法末尾添加以下内容:
if (conn != null) {
try {
conn.close();
} catch (SQLException e) { /* ignored */}
}
Run Code Online (Sandbox Code Playgroud)
但后来我得到:“声明关闭后不允许进行任何操作。”
这是我的代码:
public class DB_Connection {
String url = "XXX";
Statement statement;
public DB_Connection (){
try {
Connection con = (Connection) DriverManager.getConnection(url);
statement = (Statement) con.createStatement();
}
catch (SQLException ex){
System.out.println("Failed connection");
}
}
public void addSubject(String subject) throws SQLException {
try {
statement.executeUpdate("INSERT INTO `Subject` VALUES ('" + subject + "')" );
System.out.println("Added " + subject …Run Code Online (Sandbox Code Playgroud)