小编use*_*412的帖子

无法到达 docker 容器 - 端口未绑定

首先设置:

没有 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 …

networking docker dockerfile

14
推荐指数
1
解决办法
2万
查看次数

PyQT线程最简单的方法

我在PyQt中有一个带有函数的GUI addImage(image_path).很容易想象,当应该将新图像添加到QListWidget中时调用它.为了检测文件夹中的新图像,我使用threading.Threadwith watchdog来检测文件夹中的文件更改,然后该线程addImage直接调用.

QPixmap由于线程安全的原因,这会产生不应在gui线程外部调用的警告.

使线程安全的最佳和最简单的方法是什么?QThread的?信号/插槽?QMetaObject.invokeMethod?我只需要从线程传递一个字符串addImage.

python qt pyqt thread-safety python-watchdog

8
推荐指数
2
解决办法
2万
查看次数

使用开放 CV 进行畸变校正

我正在尝试使用开放式 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)

python opencv calibration distortion camera-calibration

5
推荐指数
1
解决办法
3543
查看次数

Python itertools 创建随机子集的迭代器

我有一个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对象中的元素数量。

有什么办法可以做到这一点吗?

python random iterator python-itertools

4
推荐指数
1
解决办法
1615
查看次数

Linux Framebuffer正确设置分辨率

我有一个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变大等。

我做错了什么?

linux graphics framebuffer raspbian

4
推荐指数
1
解决办法
2万
查看次数

在 Windows 上链接 gRPC for VisualC++

我正在尝试在 Visual C++ 项目中使用 gRPC。

到目前为止我有:

1) 构建gRPCvcpkg2 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)

visual-studio visual-c++ grpc

4
推荐指数
1
解决办法
3928
查看次数

使用 PIL 粘贴的图像会产生伪影

我有一堆图像,需要在其上放置文本叠加层。我使用 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 中看起来像这样:

覆盖 Gimp

所以我希望看到一些漂亮的黑色文本,而不是这种五颜六色的混乱。

有任何想法吗?我缺少一些 PIL 选项吗?

python png transparency python-imaging-library

3
推荐指数
1
解决办法
1604
查看次数