我正在运行以下代码,并试图修改路径,但是仍然无法解决问题。在这里,异常部分正在执行,而try块未在执行。
代码:
import cv2
import numpy as np
image = cv2.imread("C:\\test_image.jpg")
try:
cv2.imshow('result', image)
cv2.waitKey(0)
except:
print("Here")
答案 0 :(得分:1)
我猜路径不正确。尝试将反斜杠加倍,例如C:\ test_image.jpg
答案 1 :(得分:0)
您的路径不正确
struct GradientTest
{
Gradient gradient;
// Rectangles we check to move gradients' colors around
Rect* keyRects = nullptr;
bool mouseIsDownOverKey = false;
int selectedKeyIndex = 0;
void HandleInput()
{
int numKey = gradient.colorKeys.size();
if (Input::ButtonClicked(Button_Left)) {
for (int i = 0; i < numKey; i++) {
if (keyRects[i].CheckPoint(Input::getMousePosition())) {
mouseIsDownOverKey = true;
selectedKeyIndex = i;
break;
}
}
if (!mouseIsDownOverKey) {
float keyTime = InverseLerp(0.0f, 512.0f, Input::getMouseX());
Color color(rand() % 255, rand() % 255, rand() % 255, 255);
selectedKeyIndex = gradient.AddKey(color, keyTime);
mouseIsDownOverKey = true;
}
}
if (mouseIsDownOverKey) {
float keyTime = InverseLerp(0.0f, 512.0f, Input::getMouseX());
gradient.UpdateKeyTime(selectedKeyIndex, keyTime);
}
if (!Input::ButtonDown(Button_Left)) {
mouseIsDownOverKey = false;
}
}
void Update()
{
int numKey = gradient.colorKeys.size();
keyRects = new Rect[numKey];
float rectW = 10.0f;
float rectH = 20.0f;
float gradientTextureW = 512.0f;
float offset = 5.0f;
// actual texture h is 1, but I scale it up a bit
float gradientTextureH = 100.0f;
for (int i = 0; i < numKey; ++i) {
auto key = gradient.getKey(i);
keyRects[i] = Rect(512.0f * key.time - offset, gradientTextureH + rectH, rectW, rectH);
}
HandleInput();
delete[] keyRects;
}
};