当前位置: 首页 > news >正文

.NET SixLabors.ImageSharp v1.0 图像实用程序控制台示例

使用 C# 控制台应用程序示例在 Windows、Linux 和 MacOS 机器上处理图像,包括创建散点图和直方图,以及根据需要旋转图像以便正确显示。
这个小型实用程序库需要将 NuGet SixLabors.ImageSharp包(版本 1.0.4)添加到.NET Core 3.1/ .NET 6 / .NET 8项目中。它与Windows、Linux和 MacOS兼容。

这已针对ImageSharp v3.0.1 进行了重新设计。

它可以根据百万像素数或长度乘以宽度来调整图像大小,并根据需要保留纵横比。

它根据EXIF数据旋转/翻转图像。这是为了适应移动设备。

它还创建散点图和直方图。

using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Metadata.Profiles.Exif;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Formats.Png;
using System.IO;
using System;
using SixLabors.ImageSharp.Formats.Jpeg;

namespace ImageUtil
{
    public class GetSize
    {
        public GetSize(Stream stream)
        {
            using (Image iOriginal = Image.Load(stream))
            {
                stream.Position = 0;
                Width = iOriginal.Width;
                Height = iOriginal.Height;
            }
        }

        /// <summary>
        /// The width of the image specified in the class constructor's Stream parameter
        /// </summary>
        public int Width { get; }

        /// <summary>
        /// The height of the image specified in the class constructor's Stream parameter
        /// </summary>
        public int Height { get; }
    }

    public static class Resize
    {
        /// <summary>
        /// Resize and save an image to a Stream specifying its new width and height
        /// </summary>
        public static void SaveImage(Stream imageStream, int newWidth, int newHeight, bool preserveImageRatio, Stream saveToStream, int jpegQuality = 100)
        {
            using (Image iOriginal = Image.Load(imageStream))
            {
                imageStream.Position = 0;
                if (preserveImageRatio)
                {
                    float percentWidth = newWidth / (float)iOriginal.Width;
                    float percentHeight = newHeight / (float)iOriginal.Height;
                    float percent = percentHeight < percentWidth ? percentHeight : percentWidth;
                    newWidth = (int)Math.Round(iOriginal.Width * percent, 0);
                    newHeight = (int)Math.Round(iOriginal.Height * percent, 0);
                }
                resize(imageStream, iOriginal, newWidth, newHeight, saveToStream, jpegQuality);
            }
        }

        /// <summary>
        /// Resize and save an image to a Stream specifying the number of pixels to resize to
        /// </summary>
        public static void SaveImage(Stream imageStream, int newNumberOfPixels, Stream saveToStream, int jpegQuality = 100)
        {
            using (Image iOriginal = Image.Load(imageStream))
            {
                imageStream.Position = 0;
                double ratio = Math.Sqrt(newNumberOfPixels / (double)(iOriginal.Width * iOriginal.Height));
                resize(imageStream, iOriginal, (int)Math.Round(iOriginal.Width * ratio, 0), (int)Math.Round(iOriginal.Height * ratio, 0), saveToStream, jpegQuality);
            }
        }

        private static void resize(Stream origSource, Image image, int newWidth, int newHeight, Stream saveTo, int jpegQuality)
        {
            image.Mutate(x => x.Resize(newWidth, newHeight));
            transformImage(image); // NOTE: transform image AFTER resizing it!!!
            var format = Image.DetectFormat(origSource);
            if (format.Name.ToLower() == "jpeg")
            {
                var encoder = new JpegEncoder();
                encoder.Quality = jpegQuality;
                image.SaveAsJpeg(saveTo, encoder);
            }
            else
                image.Save(saveTo, format);
        }
        private static void transformImage(Image image)
        {
            IExifValue exifOrientation = image.Metadata?.ExifProfile?.GetValue(ExifTag.Orientation);

            if (exifOrientation == null)
                return;

            RotateMode rotateMode;
            FlipMode flipMode;
            setRotateFlipMode(exifOrientation, out rotateMode, out flipMode);

            image.Mutate(x => x.RotateFlip(rotateMode, flipMode));
            image.Metadata.ExifProfile.SetValue(ExifTag.Orientation, (ushort)1);
        }
        private static void setRotateFlipMode(IExifValue exifOrientation, out RotateMode rotateMode, out FlipMode flipMode)
        {
            var orientation = (ushort)exifOrientation.GetValue();

            switch (orientation)
            {
                case 2:
                    rotateMode = RotateMode.None;
                    flipMode = FlipMode.Horizontal;
                    break;
                case 3:
                    rotateMode = RotateMode.Rotate180;
                    flipMode = FlipMode.None;
                    break;
                case 4:
                    rotateMode = RotateMode.Rotate180;
                    flipMode = FlipMode.Horizontal;
                    break;
                case 5:
                    rotateMode = RotateMode.Rotate90;
                    flipMode = FlipMode.Horizontal;
                    break;
                case 6:
                    rotateMode = RotateMode.Rotate90;
                    flipMode = FlipMode.None;
                    break;
                case 7:
                    rotateMode = RotateMode.Rotate90;
                    flipMode = FlipMode.Vertical;
                    break;
                case 8:
                    rotateMode = RotateMode.Rotate270;
                    flipMode = FlipMode.None;
                    break;
                default:
                    rotateMode = RotateMode.None;
                    flipMode = FlipMode.None;
                    break;
            }
        }
    }

    /* CREATE A SCATTER PLOT JPEG/PNG IMAGE */
    public static class ScatterPlot
    {
        static readonly Rgba32 WHITE = new Rgba32(255, 255, 255);
        static readonly Rgba32 BLACK = new Rgba32(0, 0, 0);
        static readonly Rgba32 RED = new Rgba32(255, 0, 0);
        static readonly Rgba32 BLUE = new Rgba32(0, 0, 255);
        static readonly Rgba32 GREEN = new Rgba32(0, 192, 0);
        static readonly Rgba32 PURPLE = new Rgba32(128, 0, 128);
        static readonly Rgba32 ORANGE = new Rgba32(255, 164, 0);
        static readonly Rgba32 YELLOW = new Rgba32(255, 225, 0);
        static readonly Rgba32 MAGENTA = new Rgba32(255, 0, 255);
        static readonly Rgba32 AQUA = new Rgba32(0, 225, 255);
        static readonly Rgba32 BLUEJEAN = new Rgba32(0, 128, 255);
        static readonly Rgba32 BROWN = new Rgba32(150, 75, 50);
        static readonly Rgba32 CHARTREUSE = new Rgba32(223, 255, 0);
        static readonly Rgba32 DODGERBLUE = new Rgba32(30, 144, 255);
        static readonly Rgba32 NAVY = new Rgba32(0, 0, 128);
        static readonly Rgba32 DARKRED = new Rgba32(139, 0, 0);
        static readonly Rgba32[] colors = new Rgba32[] { WHITE, BLACK, RED, BLUE, GREEN, PURPLE, ORANGE, YELLOW, MAGENTA, AQUA, BLUEJEAN, BROWN, DODGERBLUE, CHARTREUSE, NAVY, DARKRED };
        public static void CreateJPEG(Stream stream, ScatterPlotColors backgroundColor, IEnumerable<PlotPoint> points, int width, int height, int pointSize, int jpegQuality = 100)
        {
            using (var bmp = new Image<Rgba32>(width / pointSize + 6, height / pointSize + 6, colors[(int)backgroundColor]))
                create(stream, width, height, bmp, points, pointSize, new JpegEncoder() { Quality = jpegQuality });
        }
        public static void CreateJPEG(string filename, ScatterPlotColors backgroundColor, IEnumerable<PlotPoint> points, int width, int height, int pointSize, int jpegQuality = 100)
        {
            using (var stream = File.Create(filename))
                CreateJPEG(stream, backgroundColor, points, width, height, pointSize, jpegQuality);
        }

        public static void CreatePNG(Stream stream, IEnumerable<PlotPoint> points, int width, int height, int pointSize)
        {
            using (var bmp = new Image<Rgba32>(width / pointSize + 6, height / pointSize + 6))
                create(stream, width, height, bmp, points, pointSize, new PngEncoder());
        }
        public static void CreatePNG(string filename, IEnumerable<PlotPoint> points, int width, int height, int pointSize)
        {
            using (var stream = File.Create(filename))
                CreatePNG(stream, points, width, height, pointSize);
        }

        private static double normalize(float min, float max, float value)
        {
            double x = max - min;
            if(x == 0)
                return 0;
            return (value - min) / x;
        }

        private static void create(Stream stream, int width, int height, Image<Rgba32> bmp, IEnumerable<PlotPoint> points, int pointSize, SixLabors.ImageSharp.Formats.IImageEncoder imageEncoder)
        {
            float xMax = float.MinValue, xMin = float.MaxValue, yMax = float.MinValue, yMin = float.MaxValue;
            foreach (var pt in points)
            {
                xMax = Math.Max(pt.x, xMax);
                xMin = Math.Min(pt.x, xMin);
                yMax = Math.Max(pt.y, yMax);
                yMin = Math.Min(pt.y, yMin);
            }
            float xDelta = Math.Max(1, xMax - xMin), yDelta = Math.Max(1, yMax - yMin);
            int w = width / pointSize;
            int h = height / pointSize;
            foreach (var pt in points)
            {
                int x = (int)(w * normalize(xMin, xMax, pt.x));
                int y = (int)(h * normalize(yMin, yMax, pt.y));
                bmp[x + 3, y + 3] = colors[((int)pt.color) % colors.Length];
            }
            bmp.Mutate(x => x.Flip(FlipMode.Vertical));
            bmp.Mutate(x => x.Resize(width, height));
            bmp.Save(stream, imageEncoder);
        }
    }
    public class PlotPoint
    {
        public ScatterPlotColors color { get; }
        public float x { get; }
        public float y { get; }
        public PlotPoint(float x, float y, ScatterPlotColors color)
        {
            this.x = x;
            this.y = y;
            this.color = color;
        }
    }
    public enum ScatterPlotColors
    {
        WHITE,
        BLACK,
        RED,
        BLUE,
        GREEN,
        PURPLE,
        ORANGE,
        YELLOW,
        MAGENTA,
        AQUA,
        BLUEJEAN,
        BROWN,
        CHARTREUSE,
        DODGERBLUE,
        NAVY,
        DARKRED
    }

    /* CREATE A PNG HISTOGRAM OF AN IMAGE */
    public static class Histogram
    {
        /// <summary>
        /// Create a histogram from the data in a stream
        /// </summary>
        public static MemoryStream CreatePNG(Stream stream, int width, int height, LRGB lrgb, byte alphaChannel = 128, bool clipBlackAndWhite = true, byte luminanceShade = 255)
        {
            using (var bmp = Image<Rgb24>.Load(stream))
            {
                return create(bmp, width, height, lrgb, alphaChannel, clipBlackAndWhite, luminanceShade);
            }
        }

        /// <summary>
        /// Create a histogram from the data in a file
        /// </summary>
        public static MemoryStream CreatePNG(string filename, int width, int height, LRGB lrgb, byte alphaChannel = 128, bool clipBlackAndWhite = true, byte luminanceShade = 255)
        {
            using (var bmp = Image<Rgb24>.Load(filename))
            {
                return create(bmp, width, height, lrgb, alphaChannel, clipBlackAndWhite, luminanceShade);
            }
        }

        private static MemoryStream create(Image bmp, int width, int height, LRGB lrgb, byte alpha, bool clip, byte shade)
        {
            ulong[] lumin = new ulong[256];
            ulong[] red = new ulong[256];
            ulong[] green = new ulong[256];
            ulong[] blue = new ulong[256];
            var bred = (lrgb & LRGB.RED) != 0;
            var bgreen = (lrgb & LRGB.GREEN) != 0;
            var bblue = (lrgb & LRGB.BLUE) != 0;
            var blumin = (lrgb == LRGB.LUMINANCE);
            int w = bmp.Width;
            int h = bmp.Height;
            var bmp2 = bmp.CloneAs<Rgb24>();
            for (int y = 0; y < h; y++)
            {
                Span<Rgb24> pixelRow = bmp2.GetPixelRowSpan(y);
                for (int x = 0; x < w; x++)
                {
                    var c = pixelRow[x];
                    lumin[(int)Math.Round((c.R + c.G + c.B) / 3.0)]++;
                    red[c.R]++;
                    green[c.G]++;
                    blue[c.B]++;
                }
            }
            ulong max = 0;
            int a = (clip ? 1 : 0), b = (clip ? 255 : 256);
            for (int i = a; i < b; i++)
            {
                if (!blumin)
                {
                    if (bred)
                        if (max < red[i])
                            max = red[i];
                    if (bgreen)
                        if (max < green[i])
                            max = green[i];
                    if (bblue)
                        if (max < blue[i])
                            max = blue[i];
                }
                else if (max < lumin[i])
                    max = lumin[i];
            }
            double HEIGHTFACTOR = 256.0 / max;
            if (blumin)
            {
                using (var bmplum = new Image<Rgba32>(256, 256))
                {
                    var penlum = new VerticalPen(new Rgba32(shade, shade, shade, alpha));
                    for (int i = 0; i < 256; i++)
                        penlum.Draw(bmplum, i, (int)(lumin[i] * HEIGHTFACTOR));
                    bmplum.Mutate(x => x.Resize(width, height));
                    MemoryStream ms = new MemoryStream();
                    bmplum.Save(ms, new PngEncoder());
                    return ms;
                }
            }
            else
            {
                using (var bmppre = new Image<Rgba32>(256, 256))
                {
                    Image<Rgba32>? bmpred = null, bmpgreen = null, bmpblue = null;
                    VerticalPen? penred = null, pengreen = null, penblue = null;
                    if (bred)
                    {
                        bmpred = new Image<Rgba32>(256, 256);
                        penred = new VerticalPen(new Rgba32(255, 0, 0, alpha));
                    }
                    if (bgreen)
                    {
                        bmpgreen = new Image<Rgba32>(256, 256);
                        pengreen = new VerticalPen(new Rgba32(0, 255, 0, alpha));
                    }
                    if (bblue)
                    {
                        bmpblue = new Image<Rgba32>(256, 256);
                        penblue = new VerticalPen(new Rgba32(0, 0, 255, alpha));
                    }

                    for (int i = 0; i < 256; i++)
                    {
                        if (bred)
                            penred.Draw(bmpred, i, (int)(red[i] * HEIGHTFACTOR));
                        if (bgreen)
                            pengreen.Draw(bmpgreen, i, (int)(green[i] * HEIGHTFACTOR));
                        if (bblue)
                            penblue.Draw(bmpblue, i, (int)(blue[i] * HEIGHTFACTOR));
                    }

                    if (bred)
                    {
                        bmppre.Mutate(x => x.DrawImage(bmpred, 1));
                        bmpred.Dispose();
                    }
                    if (bgreen)
                    {
                        bmppre.Mutate(x => x.DrawImage(bmpgreen, 1));
                        bmpgreen.Dispose();
                    }
                    if (bblue)
                    {
                        bmppre.Mutate(x => x.DrawImage(bmpblue, 1));
                        bmpblue.Dispose();
                    }
                    bmppre.Mutate(x => x.Resize(width, height));
                    MemoryStream ms = new MemoryStream();
                    bmppre.Save(ms, new PngEncoder());
                    return ms;
                }
            }
        }
        internal class VerticalPen
        {
            private readonly Rgba32 color;
            public VerticalPen(Rgba32 color)
            {
                this.color = color;
            }
            public void Draw(Image<Rgba32> bmp, int row, int height)
            {
                if (height <= bmp.Height)
                    for (int y = height - 1; y >= 0; y--)
                        bmp[row, bmp.Height - 1 - y] = color;
            }
        }
        public enum LRGB
        {
            LUMINANCE = 0,
            RED = 1,
            GREEN = 2,
            BLUE = 4,
            REDBLUE = 1 | 4,
            REDGREEN = 1 | 2,
            BLUEGREEN = 2 | 4,
            REDGREENBLUE = 1 | 2 | 4
        }
    }
}

示例用法
另请参阅:Web 应用程序示例
namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            if(args.Length > 0)
            {
                using (var openfs = System.IO.File.OpenRead(args[0]))
                {
                    // NOTE: GET IMAGE SIZE
                    var size = new ImageUtil.GetSize(openfs);

                    System.Console.WriteLine("IMAGE SIZE: " + size.Width + " x " + size.Height);

                    if (args.Length > 1)
                    {
                        if (System.IO.File.Exists(args[1]))
                            System.IO.File.Delete(args[1]);
                        using (var savefs = System.IO.File.OpenWrite(args[1]))
                        {
                            System.Console.WriteLine("RESIZING IMAGE TO 10K PIXEL THUMBNAIL");

                            // NOTE: RESIZE IMAGE TO 10K PIXELS; THIS WILL ALSO FLIP AND ROTATE IMAGE AS NEEDED
                            ImageUtil.Resize.SaveImage(openfs, 10000, savefs);
                        }
                    }
                }

                System.Console.WriteLine("CREATING LUMINANCE HISTOGRAM: histogram.png");

                // NOTE: CREATE HISTOGRAM WHICH IS RETURNED AS A MEMORY STREAM OF A PORTABLE NETWORK GRAPHICS (PNG) IMAGE FILE
                using (var histogram = ImageUtil.Histogram.CreatePNG(args[0], 300, 150, ImageUtil.Histogram.LRGB.LUMINANCE, 128))
                {
                    if (System.IO.File.Exists("histogram.png"))
                        System.IO.File.Delete("histogram.png");
                    System.IO.File.WriteAllBytes("histogram.png", histogram.ToArray());
                }
            }
            else
                System.Console.WriteLine("argument one is path to image, argument two [optional] is path to resized image");
        }
    }
}

如果您喜欢此文章,请收藏、点赞、评论,谢谢,祝您快乐每一天。 

相关文章:

.NET SixLabors.ImageSharp v1.0 图像实用程序控制台示例

使用 C# 控制台应用程序示例在 Windows、Linux 和 MacOS 机器上处理图像&#xff0c;包括创建散点图和直方图&#xff0c;以及根据需要旋转图像以便正确显示。 这个小型实用程序库需要将 NuGet SixLabors.ImageSharp包&#xff08;版本 1.0.4&#xff09;添加到.NET Core 3.1/ …...

EasyExcel提取excel文档

目录 一、前言二、提取excel文档2.1、所有sheet----获取得到headerList和总行数2.2、所有sheet----获取合并单元格信息2.3、读取某个sheet的每行数据一、前言 EasyExcel 是阿里巴巴开源的一个高性能 Excel 读写库,相比于 Apache POI 和 JXL,它有明显的优势,特别是在处理大数…...

第十五届蓝桥杯嵌入式省赛真题(满分)

第十五届蓝桥杯嵌入式省赛真题 目录 第十五届蓝桥杯嵌入式省赛真题 一、题目 二、分析 1、配置 2、变量定义 3、LCD显示模块 4、按键模块 5、数据分析和处理模块 1、频率突变 2、频率超限 3、数据处理 三、评价结果 一、题目 二、分析 1、配置 首先是配置cubemx…...

ASP.NET Core Web应用(.NET9.0)读取数据库表记录并显示到页面

1.创建ASP.NET Core Web应用 选择.NET9.0框架 安装SqlClient依赖包 2.实现数据库记录读取: 引用数据库操作类命名空间 创建查询记录结构类 查询数据并返回数据集合 3.前端遍历数据并动态生成表格显示 生成结果:...

【Sceneform-EQR】实现3D场景背景颜色的定制化(背景融合的方式、Filament材质定制)

写在前面的话 Sceneform-EQR是基于&#xff08;filament&#xff09;扩展的一个用于安卓端的渲染引擎。故本文内容对Sceneform-EQR与Filament都适用。 需求场景 在使用Filament加载三维场景的过程中&#xff0c;一个3D场景对应加载一个背景纹理。而这样的话&#xff0c;即便…...

LeetCode1706

LeetCode1706 目录 LeetCode1706题目描述示例题目理解问题描述 示例分析思路分析问题核心 代码段代码逐行讲解1. 获取网格的列数2. 初始化结果数组3. 遍历每个球4. 逐行模拟下落过程5. 检查是否卡住6. 记录结果7. 返回结果数组 复杂度分析时间复杂度空间复杂度 总结的知识点1. …...

2517. 礼盒的最大甜蜜度(Maximum Tastiness of Candy Box)

2517. 礼盒的最大甜蜜度&#xff08;Maximum Tastiness of Candy Box&#xff09; 问题描述 给定一个正整数数组 price&#xff0c;其中 price[i] 表示第 i 类糖果的价格&#xff0c;另给定一个正整数 k。商店将 k 类不同糖果组合成礼盒出售。礼盒的甜蜜度是礼盒中任意两种糖…...

Golang 的字符编码与 regexp

前言 最近在使用 Golang 的 regexp 对网络流量做正则匹配时&#xff0c;发现有些情况无法正确进行匹配&#xff0c;找到资料发现 regexp 内部以 UTF-8 编码的方式来处理正则表达式&#xff0c;而网络流量是字节序列&#xff0c;由其中的非 UTF-8 字符造成的问题。 我们这里从 G…...

利用ollama 与deepseek r1大模型搭建本地知识库

1.安装运行ollama ollama下载 https://ollama.com/download/windows 验证ollama是否安装成功 ollama --version 访问ollama本地地址&#xff1a; http://localhost:11434/ 出现如下界面 ollama运行模型 ollama run llama3.2 ollama常用操作命令 启动 Ollama 服务&#xf…...

Java短信验证功能简单使用

注册登录阿里云官网&#xff1a;https://www.aliyun.com/ 搜索短信服务 自己一步步申请就可以了 开发文档&#xff1a; https://next.api.aliyun.com/api-tools/sdk/Dysmsapi?version2017-05-25&languagejava-tea&tabprimer-doc 1.引入依赖 <dependency>…...

CAS单点登录(第7版)21.可接受的使用政策

如有疑问&#xff0c;请看视频&#xff1a;CAS单点登录&#xff08;第7版&#xff09; 可接受的使用政策 概述 可接受的使用政策 CAS 也称为使用条款或 EULA&#xff0c;它允许用户在继续应用程序之前接受使用策略。此功能的生产级部署需要修改流&#xff0c;以便通过外部存…...

53倍性能提升!TiDB 全局索引如何优化分区表查询?

作者&#xff1a; Defined2014 原文来源&#xff1a; https://tidb.net/blog/7077577f 什么是 TiDB 全局索引 在 TiDB 中&#xff0c;全局索引是一种定义在分区表上的索引类型&#xff0c;它允许索引分区与表分区之间建立一对多的映射关系&#xff0c;即一个索引分区可以对…...

Pythong 解决Pycharm 运行太慢

Pythong 解决Pycharm 运行太慢 官方给Pycharm自身占用的最大内存设低估了限制,我的Pycharm刚开始默认是256mb。 首先找到自己的Pycharm安装目录 根据合适自己的改 保存&#xff0c;重启Pycharm...

库里存储的数据有大量回车时,该如何进行存取

如图&#xff0c;打印模板存了很多坐标性的字段数据&#xff1a; 大量带换行的文本数据存到库里之后取出&#xff0c;前端需要做非空、合法校验&#xff0c; 然后在循环中&#xff0c;使用eval 函数接收每一句字符串&#xff0c;去执行这句 JavaScript 代码。 let arrStr tem…...

【devops】Github Actions Secrets | 如何在Github中设置CI的Secret供CI的yaml使用

一、Github Actions 1、ci.yml name: CIon: [ push ]jobs:build:runs-on: ubuntu-lateststeps:- name: Checkout codeuses: actions/checkoutv3- name: Set up Gouses: actions/setup-gov4with:go-version: 1.23.0- name: Cache Go modulesuses: actions/cachev3with:path: |…...

体验 DeepSeek-R1:解密 1.5B、7B、8B 版本的强大性能与应用

文章目录 &#x1f34b;引言&#x1f34b;DeepSeek 模型简介&#x1f34b;版本更新&#xff1a;1.5B、7B、8B 的区别与特点&#x1f34b;模型评估&#x1f34b;体验 DeepSeek 的过程&#x1f34b;总结 &#x1f34b;引言 随着大规模语言模型的持续发展&#xff0c;许多模型在性…...

一文说清楚什么是Token以及项目中使用Token延伸的问题

首先可以参考我的往期文章&#xff0c;我这里说清楚了Cookie&#xff0c;Seesion&#xff0c;Token以及JWT是什么 其实Token你就可以理解成这是一个认证令牌就好了 详细分清Session&#xff0c;Cookie和Token之间的区别&#xff0c;以及JWT是什么东西_还分不清 cookie、sessi…...

大模型-Tool call、检索增强

大模型 Tool call 心知天气&#xff1a;https://www.seniverse.com/ 例子&#xff1a;调用天气接口 API from openai import OpenAI import requests import json """ ##### 天气接口 API 密钥获取&#xff1a;https://www.free-api.com/doc/558 ##### &quo…...

【算法】【区间和】acwing算法基础 802. 区间和 【有点复杂,但思路简单】

题目 假定有一个无限长的数轴&#xff0c;数轴上每个坐标上的数都是 0。 现在&#xff0c;我们首先进行 n 次操作&#xff0c;每次操作将某一位置 x 上的数加 c。 接下来&#xff0c;进行 m 次询问&#xff0c;每个询问包含两个整数 l 和 r&#xff0c;你需要求出在区间 [l,r] …...

Ubuntu22.04通过Docker部署Jeecgboot

程序发布环境包括docker、mysql、redis、maven、nodejs、npm等。 一、安装docker 1、用如下命令卸载旧Docker: for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done 2、安装APT环境依赖包…...

智慧工地云平台源码,基于微服务架构+Java+Spring Cloud +UniApp +MySql

智慧工地管理云平台系统&#xff0c;智慧工地全套源码&#xff0c;java版智慧工地源码&#xff0c;支持PC端、大屏端、移动端。 智慧工地聚焦建筑行业的市场需求&#xff0c;提供“平台网络终端”的整体解决方案&#xff0c;提供劳务管理、视频管理、智能监测、绿色施工、安全管…...

学习STC51单片机31(芯片为STC89C52RCRC)OLED显示屏1

每日一言 生活的美好&#xff0c;总是藏在那些你咬牙坚持的日子里。 硬件&#xff1a;OLED 以后要用到OLED的时候找到这个文件 OLED的设备地址 SSD1306"SSD" 是品牌缩写&#xff0c;"1306" 是产品编号。 驱动 OLED 屏幕的 IIC 总线数据传输格式 示意图 …...

论文浅尝 | 基于判别指令微调生成式大语言模型的知识图谱补全方法(ISWC2024)

笔记整理&#xff1a;刘治强&#xff0c;浙江大学硕士生&#xff0c;研究方向为知识图谱表示学习&#xff0c;大语言模型 论文链接&#xff1a;http://arxiv.org/abs/2407.16127 发表会议&#xff1a;ISWC 2024 1. 动机 传统的知识图谱补全&#xff08;KGC&#xff09;模型通过…...

工业自动化时代的精准装配革新:迁移科技3D视觉系统如何重塑机器人定位装配

AI3D视觉的工业赋能者 迁移科技成立于2017年&#xff0c;作为行业领先的3D工业相机及视觉系统供应商&#xff0c;累计完成数亿元融资。其核心技术覆盖硬件设计、算法优化及软件集成&#xff0c;通过稳定、易用、高回报的AI3D视觉系统&#xff0c;为汽车、新能源、金属制造等行…...

聊一聊接口测试的意义有哪些?

目录 一、隔离性 & 早期测试 二、保障系统集成质量 三、验证业务逻辑的核心层 四、提升测试效率与覆盖度 五、系统稳定性的守护者 六、驱动团队协作与契约管理 七、性能与扩展性的前置评估 八、持续交付的核心支撑 接口测试的意义可以从四个维度展开&#xff0c;首…...

全面解析各类VPN技术:GRE、IPsec、L2TP、SSL与MPLS VPN对比

目录 引言 VPN技术概述 GRE VPN 3.1 GRE封装结构 3.2 GRE的应用场景 GRE over IPsec 4.1 GRE over IPsec封装结构 4.2 为什么使用GRE over IPsec&#xff1f; IPsec VPN 5.1 IPsec传输模式&#xff08;Transport Mode&#xff09; 5.2 IPsec隧道模式&#xff08;Tunne…...

Redis的发布订阅模式与专业的 MQ(如 Kafka, RabbitMQ)相比,优缺点是什么?适用于哪些场景?

Redis 的发布订阅&#xff08;Pub/Sub&#xff09;模式与专业的 MQ&#xff08;Message Queue&#xff09;如 Kafka、RabbitMQ 进行比较&#xff0c;核心的权衡点在于&#xff1a;简单与速度 vs. 可靠与功能。 下面我们详细展开对比。 Redis Pub/Sub 的核心特点 它是一个发后…...

AGain DB和倍数增益的关系

我在设置一款索尼CMOS芯片时&#xff0c;Again增益0db变化为6DB&#xff0c;画面的变化只有2倍DN的增益&#xff0c;比如10变为20。 这与dB和线性增益的关系以及传感器处理流程有关。以下是具体原因分析&#xff1a; 1. dB与线性增益的换算关系 6dB对应的理论线性增益应为&…...

如何应对敏捷转型中的团队阻力

应对敏捷转型中的团队阻力需要明确沟通敏捷转型目的、提升团队参与感、提供充分的培训与支持、逐步推进敏捷实践、建立清晰的奖励和反馈机制。其中&#xff0c;明确沟通敏捷转型目的尤为关键&#xff0c;团队成员只有清晰理解转型背后的原因和利益&#xff0c;才能降低对变化的…...

【无标题】湖北理元理律师事务所:债务优化中的生活保障与法律平衡之道

文/法律实务观察组 在债务重组领域&#xff0c;专业机构的核心价值不仅在于减轻债务数字&#xff0c;更在于帮助债务人在履行义务的同时维持基本生活尊严。湖北理元理律师事务所的服务实践表明&#xff0c;合法债务优化需同步实现三重平衡&#xff1a; 法律刚性&#xff08;债…...