OD_01

该C++代码展示了如何使用四方向填充算法创建一个矩阵,从中心元素开始并向四周扩展,用整数或星号(*)填充空位。
摘要由CSDN通过智能技术生成
#include <iostream>
#include <vector>
#include <string>
#include <iomanip>

int main() {
    int n, m;
    // 输入矩阵的数字个数n和行数m
    std::cin >> n >> m;
    // 计算矩阵的列数cols,使用 std::vector 初始化矩阵
    int cols = n / m + 1;
    std::vector<std::vector<std::string>> matrix(m, std::vector<std::string>(cols, " "));
    int num = 1, row = 0, col = 0;
    while (num <= n) {
        // 向右填充
        while (0 <= col && col < cols && matrix[row][col] == " ") {
            matrix[row][col] = (num <= n) ? std::to_string(num) : "*";
            num++, col++;
        }
//        std::cout << "col = " << col << std::endl;
        row++, col--;
        // 向下填充
        while (0 <= row && row < m && matrix[row][col] == " ") {
            matrix[row][col] = (num <= n) ? std::to_string(num) : "*";
            num++, row++;
        }
        row--, col--;
        // 向左填充
        if (0 <= row && row < m) {
            while (0 <= col && col < cols && matrix[row][col] == " ") {
                matrix[row][col] = (num <= n) ? std::to_string(num) : "*";
                num++, col--;
            }
            col++, row--;
        }
        // 向上填充
        if (0 <= col && col < cols) {
            while (0 <= row && row < m && matrix[row][col] == " ") {
                matrix[row][col] = (num <= n) ? std::to_string(num) : "*";
                num++, row--;
            }
            row++, col++;
        }
    }
    // 输出矩阵
    for (const auto &rows: matrix) {
        for (const auto &elem: rows) {
            std::cout << std::setw(3) << std::right << elem << " ";
        }
        std::cout << std::endl;
    }
    return 0;
}
将这两个代码结合import cv2 import numpy as np import urllib.request import tensorflow as tf # 下载DeepLabv3+模型权重文件 model_url = "http://download.tensorflow.org/models/deeplabv3_mnv2_pascal_train_aug_2018_01_29.tar.gz" tar_filename = "deeplabv3_mnv2_pascal_train_aug.tar.gz" urllib.request.urlretrieve(model_url, tar_filename) # 解压缩 with tarfile.open(tar_filename, "r:gz") as tar: tar.extractall() model_filename = "deeplabv3_mnv2_pascal_train_aug/frozen_inference_graph.pb" # 加载模型 graph = tf.Graph() with graph.as_default(): od_graph_def = tf.GraphDef() with tf.io.gfile.GFile(model_filename, 'rb') as fid: serialized_graph = fid.read() od_graph_def.ParseFromString(serialized_graph) tf.import_graph_def(od_graph_def, name='') # 读取图像 image_path = "your_image.jpg" image = cv2.imread(image_path) # 进行图像分割 with tf.compat.v1.Session(graph=graph) as sess: input_tensor = graph.get_tensor_by_name('ImageTensor:0') output_tensor = graph.get_tensor_by_name('SemanticPredictions:0') output = sess.run(output_tensor, feed_dict={input_tensor: image}) # 解码并可视化分割结果 segmentation_mask = np.squeeze(output) segmentation_mask = np.uint8(segmentation_mask) segmentation_mask = cv2.resize(segmentation_mask, (image.shape[1], image.shape[0]), interpolation=cv2.INTER_NEAREST) # 显示原始图像和分割结果 cv2.imshow("Image", image) cv2.imshow("Segmentation Mask", segmentation_mask) cv2.waitKey(0) cv2.destroyAllWindows() model1 = models.CellposeModel(gpu=True, model_type='livecell') model2 = models.Cellpose(gpu=True,model_type='nuclei') model3= models.Cellpose(gpu=True,model_type='cyto2') 集成DeepLabv3+模型和cellpose模型
07-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

阿王啊子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值