当前位置: 首页 > 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环境依赖包…...

idea大量爆红问题解决

问题描述 在学习和工作中&#xff0c;idea是程序员不可缺少的一个工具&#xff0c;但是突然在有些时候就会出现大量爆红的问题&#xff0c;发现无法跳转&#xff0c;无论是关机重启或者是替换root都无法解决 就是如上所展示的问题&#xff0c;但是程序依然可以启动。 问题解决…...

【入坑系列】TiDB 强制索引在不同库下不生效问题

文章目录 背景SQL 优化情况线上SQL运行情况分析怀疑1:执行计划绑定问题?尝试:SHOW WARNINGS 查看警告探索 TiDB 的 USE_INDEX 写法Hint 不生效问题排查解决参考背景 项目中使用 TiDB 数据库,并对 SQL 进行优化了,添加了强制索引。 UAT 环境已经生效,但 PROD 环境强制索…...

UDP(Echoserver)

网络命令 Ping 命令 检测网络是否连通 使用方法: ping -c 次数 网址ping -c 3 www.baidu.comnetstat 命令 netstat 是一个用来查看网络状态的重要工具. 语法&#xff1a;netstat [选项] 功能&#xff1a;查看网络状态 常用选项&#xff1a; n 拒绝显示别名&#…...

从深圳崛起的“机器之眼”:赴港乐动机器人的万亿赛道赶考路

进入2025年以来&#xff0c;尽管围绕人形机器人、具身智能等机器人赛道的质疑声不断&#xff0c;但全球市场热度依然高涨&#xff0c;入局者持续增加。 以国内市场为例&#xff0c;天眼查专业版数据显示&#xff0c;截至5月底&#xff0c;我国现存在业、存续状态的机器人相关企…...

屋顶变身“发电站” ,中天合创屋面分布式光伏发电项目顺利并网!

5月28日&#xff0c;中天合创屋面分布式光伏发电项目顺利并网发电&#xff0c;该项目位于内蒙古自治区鄂尔多斯市乌审旗&#xff0c;项目利用中天合创聚乙烯、聚丙烯仓库屋面作为场地建设光伏电站&#xff0c;总装机容量为9.96MWp。 项目投运后&#xff0c;每年可节约标煤3670…...

spring:实例工厂方法获取bean

spring处理使用静态工厂方法获取bean实例&#xff0c;也可以通过实例工厂方法获取bean实例。 实例工厂方法步骤如下&#xff1a; 定义实例工厂类&#xff08;Java代码&#xff09;&#xff0c;定义实例工厂&#xff08;xml&#xff09;&#xff0c;定义调用实例工厂&#xff…...

uniapp中使用aixos 报错

问题&#xff1a; 在uniapp中使用aixos&#xff0c;运行后报如下错误&#xff1a; AxiosError: There is no suitable adapter to dispatch the request since : - adapter xhr is not supported by the environment - adapter http is not available in the build 解决方案&…...

OPenCV CUDA模块图像处理-----对图像执行 均值漂移滤波(Mean Shift Filtering)函数meanShiftFiltering()

操作系统&#xff1a;ubuntu22.04 OpenCV版本&#xff1a;OpenCV4.9 IDE:Visual Studio Code 编程语言&#xff1a;C11 算法描述 在 GPU 上对图像执行 均值漂移滤波&#xff08;Mean Shift Filtering&#xff09;&#xff0c;用于图像分割或平滑处理。 该函数将输入图像中的…...

Linux 中如何提取压缩文件 ?

Linux 是一种流行的开源操作系统&#xff0c;它提供了许多工具来管理、压缩和解压缩文件。压缩文件有助于节省存储空间&#xff0c;使数据传输更快。本指南将向您展示如何在 Linux 中提取不同类型的压缩文件。 1. Unpacking ZIP Files ZIP 文件是非常常见的&#xff0c;要在 …...

在Mathematica中实现Newton-Raphson迭代的收敛时间算法(一般三次多项式)

考察一般的三次多项式&#xff0c;以r为参数&#xff1a; p[z_, r_] : z^3 (r - 1) z - r; roots[r_] : z /. Solve[p[z, r] 0, z]&#xff1b; 此多项式的根为&#xff1a; 尽管看起来这个多项式是特殊的&#xff0c;其实一般的三次多项式都是可以通过线性变换化为这个形式…...