闪电问题在计算机视觉中很常见而且不是一件容易的事,但我只是想知道现在是否有适当的方法来检测和减少光反射以保存图像中的更多信息?我用OpenCV和Python尝试了几种没有运气的方法.
(带反射的图像)
(没有反射的图像)
我试图将图像分割为H,S,V颜色空间,并使用直方图均衡来均衡(V)通道.我用过Clahe均衡方法:
import cv2
import numpy as np
image = cv2.imread('glare.png')
hsv_image = cv2.cvtColor(image, cv2.COLOR_RGB2HSV)
h, s, v = cv2.split(hsv_image)
clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8,8))
v = clahe.apply(v)
hsv_image = cv2.merge([h, s, v])
hsv_image = cv2.cvtColor(hsv_image, cv2.COLOR_HSV2RGB)
cv2.imwrite('clahe_h.png', hsv_image)
Run Code Online (Sandbox Code Playgroud)
结果:
我也试图阈值图像找到明亮的空间,而不是使用Image Inpainting方法用相邻像素替换反射像素.
import cv2
import numpy as np
image = cv2.imread('glare.png')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
blurred = cv2.GaussianBlur(gray, (3,3), 0)
thresh = cv2.threshold(blurred, 225, 255, cv2.THRESH_BINARY)[1]
dst_TELEA = cv2.inpaint(image,thresh,3,cv2.INPAINT_TELEA)
cv2.imwrite('after_INPAINT.png',dst_TELEA)
Run Code Online (Sandbox Code Playgroud)
我正在运行 Nginx、Gunicorn 和 Supervisord。Supervisord 启动后,它会gunicorn.sock使用用户和组创建文件my_user:my_user。我需要 Nginx 才能连接到套接字文件,gunicorn.sock是否有任何正确的方法来设置套接字文件用户和组my_user:nginx?
我尝试将此设置设置为以下内容,[myprogram:program]但它不起作用:
socket_owner=my_user:nginx
chown=my_user:nginx
Run Code Online (Sandbox Code Playgroud)
我的supervisord.conf程序:
[myprogram:program]
command = /var/www/project/virtual_env/bin/gunicorn -k gevent --worker-connections 1001 --bind=unix:gunicorn.sock -m 007 wsgi:application
directory = /var/www/project/
autostart=true
autorestart=unexpected
Run Code Online (Sandbox Code Playgroud) 我只是想知道是否可以在 Flask 服务器上同时启动两个功能?我需要function_1在它触发后启动function_2并同时运行这两个功能。是否可以?
def function_1():
yield "start_function_2"
counter = 0
while True:
counter += 1
print counter
def function_2():
second_counter = 0
while True:
second_counter += 1
print second_counter
def main():
return render_template("index.html")
@app.route("/start_functions", methods=["POST"])
def start_functions():
data = request.data
if request.method == "POST":
for i in function_1(data):
if (i == "start_function_2"):
function_2()
if __name__ == "__main__":
app.run(dhost="0.0.0.0", port=port)
Run Code Online (Sandbox Code Playgroud) 我只是想知道是否有可能将PHP加密函数转换为Python?我使用的PHP函数加密USER ID并将其存储在Database,现在我需要解密USER ID中Python,我使用这个PHP功能:
function decrypt($id) {
$cryptKey = '123';
$decoded = rtrim( mcrypt_decrypt( MCRYPT_RIJNDAEL_256, md5( $cryptKey ), base64_decode( $id ), MCRYPT_MODE_CBC, md5( md5( $cryptKey ) ) ), "\0");
return( $decoded );
}
Run Code Online (Sandbox Code Playgroud) 我想知道是否可以将图像分成块,例如 8x8 块(64 pixels per block)并为每个块执行直方图功能并将结果保存到新图像中而不是单独的图像?
def apply_histogram(block):
h, b = np.histogram(block.flatten(), 256, normed=True)
cdf = h.cumsum()
cdf = 255 * cdf / cdf[-1]
return np.interp(block.flatten(), b[:-1], cdf).reshape(block.shape)
Run Code Online (Sandbox Code Playgroud) 我试图找到字符作为例子中的轮廓:
thresh = cv2.adaptiveThreshold(roi,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY,9,2)
_,contours, hierarchy = cv2.findContours(thresh.copy(),cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
contours = sorted(contours, key=cv2.contourArea, reverse = True)
for cnt in contours:
x,y,w,h = cv2.rectBounding(cnt)
cv2.rectangle(roi,(x,y),(x+w,y+h),(0,255,0),1)
Run Code Online (Sandbox Code Playgroud)
但是我得到的结果并不是预期的,因为字符孔会像轮廓一样返回,我可以用cv2.contourArea()宽度,高度来绕过它,但我需要用层次结构来完成它.
如果我将层次模式从cv2.RETR_TREE更改为cv2.RETR_EXTERNAL,我会在每个窗口中获得一个轮廓,例如: