>>> args = {"image": 'I:\\18Breakageratecalculation\\SVM run\\images\\001.jpg\\'} >>> image = cv2.imread(args["image"]) [ WARN:0@10.864] global loadsave.cpp:244 cv::findDecoder imread_('I:\18Breakageratecalculation\SVM run\images\001.jpg\'): can't open/read file: check file path/integrity >>> args = {"image": 'I:\18Breakageratecalculation\SVM run\images\001.jpg'}
时间: 2023-06-30 09:27:38 浏览: 71
根据您提供的代码,第一行中的 "image" 参数值似乎存在问题。它在结尾处有一个额外的反斜杠,这可能会导致 OpenCV 在读取图像时无法找到正确的文件路径。这是由于 Windows 操作系统使用反斜杠作为路径分隔符,而在 Python 字符串中反斜杠通常用作转义字符。
因此,您需要将路径中的反斜杠进行转义,或者使用原始字符串来避免这种情况。您第二行代码中的路径似乎已经进行了修正。您可以尝试下面的代码:
```
args = {"image": 'I:\\18Breakageratecalculation\\SVM run\\images\\001.jpg'}
image = cv2.imread(args["image"])
```
这应该可以成功读取图像文件。
相关问题
args = {"image": 'I:\\18Breakageratecalculation\\SVM run\\images\\030.jpg'} # load the image and apply SLIC and extract (approximately) # the supplied number of segments image = cv2.imread(args["image"]) segments = slic(img_as_float(image), n_segments=100, sigma=3) # show the output of SLIC fig = plt.figure('Superpixels') ax = fig.add_subplot(1, 1, 1) ax.imshow(mark_boundaries(img_as_float(cv2.cvtColor(image, cv2.COLOR_BGR2RGB)), segments)) plt.axis("off") plt.show()保存超像素识别结果
可以使用下面的代码来保存超像素识别结果:
```
# create a directory to store the segmented images
if not os.path.exists("segmented_images"):
os.makedirs("segmented_images")
# save the image with superpixel boundaries
plt.imsave(os.path.join("segmented_images", "superpixel_boundaries.png"), mark_boundaries(img_as_float(cv2.cvtColor(image, cv2.COLOR_BGR2RGB)), segments))
# loop over the unique segment values
for (i, segVal) in enumerate(np.unique(segments)):
# construct a mask for the segment
mask = np.zeros(image.shape[:2], dtype="uint8")
mask[segments == segVal] = 255
# apply the mask to the image
masked_image = np.multiply(image, cv2.cvtColor(mask, cv2.COLOR_GRAY2BGR) > 0)
# save the masked image as a file
filename = os.path.join("segmented_images", "segment_%d.png" % i)
cv2.imwrite(filename, masked_image)
```
这将在当前目录下创建一个名为 "segmented_images" 的文件夹,并将超像素边界图像和每个超像素块保存为单独的图像文件。
/usr/include/spdlog/logger.h:90:9: required from ‘void spdlog::logger::log(spdlog::source_loc, spdlog::level::level_enum, fmt::v8::format_string<T ...>, Args&& ...) [with Args = {cv::Rect_<int>&}; fmt::v8::format_string<T ...> = fmt::v8::basic_format_string<char, cv::Rect_<int>&>]’
这个错误提示出现在 `spdlog` 库的 `logger.h` 文件中,它表示在使用 `spdlog` 记录日志时,传递了一个 `cv::Rect_<int>&` 类型的参数,这个类型无法被格式化输出。具体来说,`fmt` 库不知道如何将这个类型转换成字符串,所以编译器报错了。
为了解决这个问题,你需要为 `cv::Rect_<int>&` 类型提供一个格式化器,告诉 `fmt` 库如何将它转换成字符串。具体的做法是,在你的代码中实现一个 `formatter<cv::Rect_<int>&>` 类型的类,然后在这个类中实现 `format` 函数,将 `cv::Rect_<int>&` 类型转换成字符串。然后将这个格式化器传递给 `spdlog::logger` 对象,让它在记录日志时使用这个格式化器。
下面是一个示例:
```c++
#include <fmt/format.h>
#include <spdlog/spdlog.h>
template <>
struct fmt::formatter<cv::Rect_<int>&> {
template <typename ParseContext>
constexpr auto parse(ParseContext& ctx) { return ctx.begin(); }
template <typename FormatContext>
auto format(const cv::Rect_<int>& rect, FormatContext& ctx) {
return fmt::format_to(ctx.out(), "{{ x:{}, y:{}, width:{}, height:{} }}", rect.x, rect.y, rect.width, rect.height);
}
};
int main() {
auto logger = spdlog::stdout_logger_mt("console");
cv::Rect_<int> rect(10, 20, 30, 40);
logger->info("Rect: {}", rect);
return 0;
}
```
在这个示例中,我们为 `cv::Rect_<int>&` 类型提供了一个格式化器 `formatter<cv::Rect_<int>&>`,然后在使用 `spdlog` 记录日志时,传递了一个 `cv::Rect_<int>&` 类型的参数,让它使用我们自己实现的格式化器输出日志。