我有一个从网上下载的图像(验证码)。

当我加载时,opencv它似乎失去了它的属性,或者只是将透明背景与深色/黑色混合:

目前,代码除了再次加载文字外什么也没做:
captchaImg = cv2.imread('captcha1.png')
cv2.imwrite("captcha2.png", captchaImg)
Run Code Online (Sandbox Code Playgroud)
我也尝试过使用选项 0、1、2、3 加载,但结果是相同的。
由于某种我无法理解的原因, open cv 函数cv2.moments返回一个字典,其中我提供的轮廓的值全部为零。这是一个 MWE:
contour = [[[271, 67]],
[[274, 67]],
[[275, 68]],
[[278, 68]],
[[279, 69]],
[[283, 69]],
[[284, 70]],
[[287, 70]],
[[288, 71]],
[[291, 71]],
[[292, 72]],
[[295, 72]],
[[292, 72]],
[[291, 71]],
[[288, 71]],
[[287, 70]],
[[284, 70]],
[[283, 69]],
[[279, 69]],
[[278, 68]],
[[275, 68]],
[[274, 67]]]
contour = np.asarray(contour)
moments = cv2.moments(contour)
Run Code Online (Sandbox Code Playgroud)
结果:
print(moments)
{'m00': 0.0, 'm10': 0.0, 'm01': 0.0, 'm20': 0.0, 'm11': 0.0, 'm02': 0.0, 'm30': 0.0, 'm21': 0.0, 'm12': 0.0, 'm03': …Run Code Online (Sandbox Code Playgroud) 我尝试使用 python 和 opencv 进行相机校准来找到相机矩阵。我使用了此链接中的以下代码
https://automaticaddison.com/how-to-perform-camera-calibration-using-opencv/
import cv2 # Import the OpenCV library to enable computer vision
import numpy as np # Import the NumPy scientific computing library
import glob # Used to get retrieve files that have a specified pattern
# Path to the image that you want to undistort
distorted_img_filename = r'C:\Users\uid20832\3.jpg'
# Chessboard dimensions
number_of_squares_X = 10 # Number of chessboard squares along the x-axis
number_of_squares_Y = 7 # Number of chessboard squares along the y-axis
nX …Run Code Online (Sandbox Code Playgroud) 我现在有更新的代码如下:
# Hyperparameters
random_seed = 123
learning_rate = 0.01
num_epochs = 10
batch_size = 128
Run Code Online (Sandbox Code Playgroud)
device = torch.device("cuda:1" if torch.cuda.is_available() else "cpu")
对于范围内的纪元(num_epochs):模型= resnet34.train()对于batch_idx,枚举(train_generator)中的(特征,目标):
features = features.to(device)
targets = targets.to(device)
### FORWARD AND BACK PROP
logits = model(features)
cost = torch.nn.functional.cross_entropy(logits, targets)
optimizer.zero_grad()
cost.backward()
### UPDATE MODEL PARAMETERS
optimizer.step()
### LOGGING
if not batch_idx % 50:
print ('Epoch: %03d/%03d | Batch %03d/%03d | Cost: %.4f'
%(epoch+1, num_epochs, batch_idx,
len(datagen)//batch_size, cost))
model = model.eval() # eval mode to prevent upd. batchnorm …Run Code Online (Sandbox Code Playgroud) 需要帮助这是我的代码:
import mediapipe as mp
mp_drawing = mp.solutions.drawing_utils # Drawing helpers
mp_holistic = mp.solutions.holistic # Mediapipe Solutions
cap = cv2.VideoCapture(0)
# Initiate holistic model
with mp_holistic.Holistic(min_detection_confidence=0.5, min_tracking_confidence=0.5) as holistic:
while cap.isOpened():
ret, frame = cap.read()
# Recolor Feed
image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
image.flags.writeable = False
# Make Detections
results = holistic.process(image)
# print(results.face_landmarks)
# face_landmarks, pose_landmarks, left_hand_landmarks, right_hand_landmarks
# Recolor image back to BGR for rendering
image.flags.writeable = True
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
# 1. Draw face landmarks
mp_drawing.draw_landmarks(image, results.face_landmarks, …Run Code Online (Sandbox Code Playgroud) 我有一个视频,我想从视频中仅提取特定的帧。
目前我所做的是:
index = [1,2,3,4,5,6,7,8]
img_list = []
for i, frame in enumerate(iio.imiter("imageio:cockatoo.mp4")):
if i in index:
img_list.append(frame)
img_array = np.asarray(img_list)
Run Code Online (Sandbox Code Playgroud)
有没有办法只“寻找”我想要的帧,就像在 opencv 中完成的那样,如此处所示?
我尝试过使用 python 中的函数反转负片图像颜色,bitwise_not()但它具有蓝色色调。我想知道如何冲洗出看起来不错的负片图像。这是我所做的结果。(我刚刚为我正在进行的新测试裁剪了负片图像,所以不要介意)
我无法生成背景被删除的图像
from rembg import remove
from PIL import Image
input_path = "crop.jpeg"
output_path = 'crop1.png'
input = Image.open(input_path)
output = remove(input)
output.save(output_path)
Run Code Online (Sandbox Code Playgroud)
我的错误为: RuntimeError: D:\a_work\1\s\onnxruntime\core\session\provider_bridge_ort.cc:1069 onnxruntime::ProviderLibrary::Get [ONNXRuntimeError] : 1 : FAIL : LoadLibrary 失败,错误 126 ""当尝试加载“C:\users\lib\site-packages\onnxruntime\capi\onnxruntime_providers_tensorrt.dll”时
我正在尝试使用 ushort 数据类型渲染两个大小为 256x256 的图像。一个必须是灰度,另一个必须是 RGB。然而,两者都渲染为黑色方块。我相信问题出在我的 openGL 纹理定义中,但我不确定。
这是我的代码的最小版本。
#include "imgui.h"
#include "imgui_impl_glfw.h"
#include "imgui_impl_opengl3.h"
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <opencv2/opencv.hpp>
using namespace cv;
int main()
{
//init glfw, window, glad, imgui
glfwInit();
const char* glsl_version = "#version 330 core";
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
GLFWwindow* window = glfwCreateWindow(600, 400, "test", NULL, NULL);
glfwMakeContextCurrent(window);
gladLoadGL();
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
ImGui::CreateContext();
ImGui::StyleColorsDark();
ImGui_ImplGlfw_InitForOpenGL(window, true);
ImGui_ImplOpenGL3_Init(glsl_version);
//define image data
ushort value;
Mat_<ushort> grey = Mat_<ushort>(256, 256);
Mat_<Vec3w> rgb = Mat_<Vec3w>(256, 256);
for …Run Code Online (Sandbox Code Playgroud) 我需要获取图像作为用户加载的视频的预览,它不需要是一个很棒的缩略图,因为它只是用于聊天应用程序,所以我想到当用户发送包含 mp4 的消息时我处理它并保存一个随机帧。
我用谷歌搜索了一下,每个人都在使用 ffmpeg,但这是一个外部软件,你只能用 java 与它交互,我的项目需要独立,我不希望它依赖于服务器安装了 ffmpeg 的事实,所以我回到过去并找到了 JavaFX,但所有在线片段都没有指定他们正在使用的版本,而且 chatGPT 一如既往地毫无用处,你们能告诉我如何做到这一点,或者至少向我解释一下它是如何工作的吗?我可以自己编码吗?我正在使用这个依赖项
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>16</version> <!-- the version chatGPT wrote but you can change that -->
</dependency>
Run Code Online (Sandbox Code Playgroud)
如果您有完全不同的解决方案,那也很棒,我只关心在指定路径上使用指定名称保存视频中的随机帧,提前致谢
我尝试了这种方法,但它给出了很多错误,可能是因为版本不匹配
private byte[] getFrameFromVideo(String videoFilePath, int targetTimeSeconds) throws IOException {
try {
Media media = new Media(new File(videoFilePath).toURI().toString());
MediaPlayer mediaPlayer = new MediaPlayer(media);
CountDownLatch latch = new CountDownLatch(1);
mediaPlayer.setOnReady(() -> {
mediaPlayer.pause();
mediaPlayer.setStartTime(mediaPlayer.getTotalDuration().multiply(targetTimeSeconds * 1.0 / media.getDuration().toSeconds()));
mediaPlayer.setStopTime(mediaPlayer.getStartTime().add(mediaPlayer.getTotalDuration().multiply(1.0 / media.getDuration().toSeconds())));
latch.countDown();
});
mediaPlayer.setOnEndOfMedia(() -> {
BufferedImage bufferedImage = new BufferedImage(mediaPlayer.getMedia().getWidth(), mediaPlayer.getMedia().getHeight(), …Run Code Online (Sandbox Code Playgroud)