首先设置:
没有 WSL2 的 Windows 10 - 旧的 Hyper-V 后端
Docker for Windows - Linux 容器。
我有一个小的 python 脚本:
from flask import Flask
server = Flask(__name__)
@server.route("/ping")
def hello():
return "Hello World!"
if __name__ == "__main__":
server.run(host='0.0.0.0')
Run Code Online (Sandbox Code Playgroud)
当我在本地运行它(没有docker)时,我可以localhost:5000/ping很好地到达。
Dockerfile:
FROM python:3.8-buster
RUN useradd -ms /bin/bash user
USER user
WORKDIR /home/user
COPY requirements.txt .
RUN pip install -r requirements.txt && rm requirements.txt
COPY app.py .
EXPOSE 5000
ENTRYPOINT [ "python", "app.py"]
Run Code Online (Sandbox Code Playgroud)
构建得很好。启动:docker container run -t test_tag -dp 5000:5000 …
我在PyQt中有一个带有函数的GUI addImage(image_path).很容易想象,当应该将新图像添加到QListWidget中时调用它.为了检测文件夹中的新图像,我使用threading.Threadwith watchdog来检测文件夹中的文件更改,然后该线程addImage直接调用.
QPixmap由于线程安全的原因,这会产生不应在gui线程外部调用的警告.
使线程安全的最佳和最简单的方法是什么?QThread的?信号/插槽?QMetaObject.invokeMethod?我只需要从线程传递一个字符串addImage.
我正在尝试使用开放式 CV 来校正图像失真。我试图纠正的失真理论是桶形和枕形失真的组合,如下所示:
我在这里不使用普通相机,而是使用检流计扫描系统(如下所示: http: //www.chinagalvo.com/Content/uploads/2019361893/201912161511117936592.gif),所以我不能只记录像这样的棋盘图案所有 OpenCV 指南都建议。
但我可以将扫描仪移动到目标位置并测量激光束在图像平面中的实际位置,例如绘制为:
所以我将这些值放入此脚本中的 OpenCVcalibrateCamera函数中:
import numpy as np
import cv2
targetPosX = np.array([-4., -2., 0., 2., 4., -4., -2., 0., 2., 4., -4., -2., 2., 4., -4., -2., 0., 2., 4., -4., -2., 0., 2., 4.])
targetPosY = np.array([-4., -4., -4., -4., -4., -2., -2., -2., -2., -2., 0., 0., 0., 0., 2., 2., 2., 2., 2., 4., 4., 4., 4., 4.])
actualPosX = np.array([-4.21765834, -2.14708042, -0.07755157, 1.9910175, 4.05941744, -4.17816164, …Run Code Online (Sandbox Code Playgroud) 我有一个itertools.combinations(big_matrix,50)带有 的迭代器big_matrix.shape = (65,x),所以大约有 10^14 种组合。我想获得 10000 个这样的组合的随机子集,也作为迭代器,以节省内存。
我尝试了 itertools 食谱
def random_combination(iterable, r):
"Random selection from itertools.combinations(iterable, r)"
pool = tuple(iterable)
n = len(pool)
indices = sorted(random.sample(xrange(n), r))
return tuple(pool[i] for i in indices)
Run Code Online (Sandbox Code Playgroud)
但tuple(iterable)会创建一个包含 10^14 个值的元组,并且该函数不返回迭代器而是返回数组。
random.sample不起作用,因为它无法获取itertools.combinations对象中的元素数量。
有什么办法可以做到这一点吗?
我有一个RaspberryPi,想在没有xserver的情况下全屏显示图像-因此直接将其写入帧缓冲区。没问题
但是将其全屏设置是行不通的。
cat /sys/class/graphics/fb0/modes
Run Code Online (Sandbox Code Playgroud)
产量:
U:1024x768p-0
U:1920x1200p-0
U:1920x1080p-0
U:608x684p-0
Run Code Online (Sandbox Code Playgroud)
所以我用
fbset -xres 1920 -yres 1200 -match
Run Code Online (Sandbox Code Playgroud)
导致
>>fbset
mode "1920x1200"
geometry 1920 1200 1920 1200 16
timings 0 0 0 0 0 0 0
rgba 5/11,6/5,5/0,0/16
endmode
Run Code Online (Sandbox Code Playgroud)
如果我现在用于fbi显示图像,或仅填充framebuffer /dev/urandom >> /dev/fb0,则仅填充部分屏幕。显示部分的长宽比等正确,周围只有一个大的黑色边界。
如果我使用其他分辨率,一切都会按预期运行,例如fbi中的stats-line变大等。
我做错了什么?
我正在尝试在 Visual C++ 项目中使用 gRPC。
到目前为止我有:
1) 构建gRPC:vcpkg2 vcpkg install grpc:x64-windows
) 将vcpgk库与 Visual Studio 集成:vcpkg integrate install
到目前为止,一切都很好——智能感知自动完成命名空间等。
我的客户端cpp文件如下所示:
#include "pch.h"
#include <iostream>
#include <memory>
#include <string>
#include <grpcpp\grpcpp.h>
#include "GRPCServerInterface.grpc.pb.h"
#include "FileFormat.pb.h"
using grpc::Channel;
using grpc::ClientContext;
using grpc::Status;
using namespace GRPCServerInterface;
int main()
{
std::cout << "Hello World!\n";
// prepare send message & payload
IsFormatSupportedInput msg;
msg.set_fileextension(".asp");
// prepare reply
IsFormatSupportedOutput rpl;
// connect
FileHandler::Stub ClientStub = FileHandler::Stub(grpc::CreateChannel("localhost:50051", grpc::InsecureChannelCredentials())); …Run Code Online (Sandbox Code Playgroud) 我有一堆图像,需要在其上放置文本叠加层。我使用 GIMP(具有透明度的 PNG)创建了叠加层,并尝试将其粘贴到其他图像的顶部:
from PIL import Image
background = Image.open("hahn_echo_1.png")
foreground = Image.open("overlay_step_3.png")
background.paste(foreground, (0, 0), foreground)
background.save("abc.png")
Run Code Online (Sandbox Code Playgroud)
然而,我得到的不是在顶部显示漂亮的黑色文本,而是:
overlay.png 在 Gimp 中看起来像这样:
所以我希望看到一些漂亮的黑色文本,而不是这种五颜六色的混乱。
有任何想法吗?我缺少一些 PIL 选项吗?
python ×4
calibration ×1
distortion ×1
docker ×1
dockerfile ×1
framebuffer ×1
graphics ×1
grpc ×1
iterator ×1
linux ×1
networking ×1
opencv ×1
png ×1
pyqt ×1
qt ×1
random ×1
raspbian ×1
transparency ×1
visual-c++ ×1