1.如何通过c#读写(JPG格式)的摘要信息
2.å¦ä½ç¼è¯Windowsä¸çOpenOCD
3.Opencv中的两种去畸变函数
如何通过c#读写(JPG格式)的摘要信息
using System;
using System.Collections.Generic;
using System.Text;
namespace SnhjCms.Common
{
/// <summary>
/// 处理类
/// </summary>
public static class PictureUtil
{
/// <summary>
/// 生成缩略图
/// </summary>
/// <param name="imgPath">原路径</param>
/// <param name="breviaryPath">缩略图路径</param>
/// <param name="width">缩略图宽度</param>
/// <param name="height">缩略图高度</param>
/// <param name="mode">生成方式</param>
public static void MakeBreviaryPhoto(string imgPath, string breviaryPath, int width, int height, string mode)
{
System.Drawing.Image image = System.Drawing.Image.FromFile(imgPath);
int x = 0, y = 0;
int w = image.Width;
int h = image.Height;
switch (mode)
{
case "HW"://指定高度和宽度缩放(会变形)
break;
case "W"://指定宽度缩放,高度按比例。
height = h * width / w;
break;
case "H"://指定高度缩放,宽度按比例。
width = w * height / h;
break;
case "Cut"://指定高度和宽度裁剪。
if ((double)w / (double)h > (double)width / (double)height)
{
w = h * width / height;
x = (image.Width - w) / 2;
}
else
{
h = w * height / width;
y = (image.Height - h) / 2;
}
break;
default:
break;
}
//创建一个bmp
System.Drawing.Image bmpImg = new System.Drawing.Bitmap(width,直播带货网站源码 height);
//新建一个画板
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmpImg);
//设置高质量插值法
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
//设置高质量,低速度呈现平滑程度
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
//清空画布并以透明背景色填充
g.Clear(System.Drawing.Color.Transparent);
//在指定位置并且按指定大小绘制原的指定部分
g.DrawImage(image, new System.Drawing.Rectangle(0,0,width,height), new System.Drawing.Rectangle(x,y,w,h), System.Drawing.GraphicsUnit.Pixel);
try
{
//以jpg格式保存缩略图
bmpImg.Save(breviaryPath, System.Drawing.Imaging.ImageFormat.Jpeg);
}
catch (Exception e)
{
throw e;
}
finally
{
image.Dispose();
bmpImg.Dispose();
g.Dispose();
}
}
/// <summary>
/// 加水印
/// </summary>
/// <param name="filename">文件名</param>
/// <param name="watermarkFilename">水印文件名</param>
/// <param name="watermarkStatus">水印位置:0=不使用 1=左上 2=中上 3=右上 4=左中 ... 9=右下</param>
/// <param name="quality">是否是高质量 取值范围0--</param>
/// <param name="watermarkTransparency">水印透明度 取值范围1-- (为不透明)</param>
public static void AddImageSignPic(string Path, string filename, string watermarkFilename, int watermarkStatus, int quality, int watermarkTransparency)
{
System.Drawing.Image img = System.Drawing.Image.FromFile(Path);
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(img);
//设置高质量插值法
//g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
//设置高质量,低速度呈现平滑程度
//g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
System.Drawing.Image watermark = new System.Drawing.Bitmap(watermarkFilename);
if (watermark.Height >= img.Height || watermark.Width >= img.Width)
{
return;
}
System.Drawing.Imaging.ImageAttributes imageAttributes = new System.Drawing.Imaging.ImageAttributes();
System.Drawing.Imaging.ColorMap colorMap = new System.Drawing.Imaging.ColorMap();
colorMap.OldColor = System.Drawing.Color.FromArgb(, 0, , 0);
colorMap.NewColor = System.Drawing.Color.FromArgb(0, 0, 0, 0);
System.Drawing.Imaging.ColorMap[] remapTable = { colorMap };
imageAttributes.SetRemapTable(remapTable, System.Drawing.Imaging.ColorAdjustType.Bitmap);
float transparency = 0.5F;
if (watermarkTransparency >= 1 && watermarkTransparency <= )
{
transparency = (watermarkTransparency / .0F);
}
float[][] colorMatrixElements = {
new float[] { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f},
new float[] { 0.0f, 1.0f, 0.0f, 0.0f, 0.0f},
new float[] { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f},
new float[] { 0.0f, 0.0f, 0.0f, transparency, 0.0f},
new float[] { 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}
};
System.Drawing.Imaging.ColorMatrix colorMatrix = new System.Drawing.Imaging.ColorMatrix(colorMatrixElements);
imageAttributes.SetColorMatrix(colorMatrix, System.Drawing.Imaging.ColorMatrixFlag.Default, System.Drawing.Imaging.ColorAdjustType.Bitmap);
int xpos = 0;
int ypos = 0;
switch (watermarkStatus)
{
case 1:
xpos = (int)(img.Width * (float).);
ypos = (int)(img.Height * (float).);
break;
case 2:
xpos = (int)((img.Width * (float).) - (watermark.Width / 2));
ypos = (int)(img.Height * (float).);
break;
case 3:
xpos = (int)((img.Width * (float).) - (watermark.Width));
ypos = (int)(img.Height * (float).);
break;
case 4:
xpos = (int)(img.Width * (float).);
ypos = (int)((img.Height * (float).) - (watermark.Height / 2));
break;
case 5:
xpos = (int)((img.Width * (float).) - (watermark.Width / 2));
ypos = (int)((img.Height * (float).) - (watermark.Height / 2));
break;
case 6:
xpos = (int)((img.Width * (float).) - (watermark.Width));
ypos = (int)((img.Height * (float).) - (watermark.Height / 2));
break;
case 7:
xpos = (int)(img.Width * (float).);
ypos = (int)((img.Height * (float).) - watermark.Height);
break;
case 8:
xpos = (int)((img.Width * (float).) - (watermark.Width / 2));
ypos = (int)((img.Height * (float).) - watermark.Height);
break;
case 9:
xpos = (int)((img.Width * (float).) - (watermark.Width));
ypos = (int)((img.Height * (float).) - watermark.Height);
break;
}
g.DrawImage(watermark, new System.Drawing.Rectangle(xpos, ypos, watermark.Width, watermark.Height), 0, 0, watermark.Width, watermark.Height, System.Drawing.GraphicsUnit.Pixel, imageAttributes);
System.Drawing.Imaging.ImageCodecInfo[] codecs = System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders();
System.Drawing.Imaging.ImageCodecInfo ici = null;
foreach (System.Drawing.Imaging.ImageCodecInfo codec in codecs)
{
if (codec.MimeType.IndexOf("jpeg") > -1)
{
ici = codec;
}
}
System.Drawing.Imaging.EncoderParameters encoderParams = new System.Drawing.Imaging.EncoderParameters();
long[] qualityParam = new long[1];
if (quality < 0 || quality > )
{
quality = ;
}
qualityParam[0] = quality;
System.Drawing.Imaging.EncoderParameter encoderParam = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, qualityParam);
encoderParams.Param[0] = encoderParam;
if (ici != null)
{
img.Save(filename, ici, encoderParams);
}
else
{
img.Save(filename);
}
g.Dispose();
img.Dispose();
watermark.Dispose();
imageAttributes.Dispose();
}
/// <summary>
/// 在上生成水印
/// </summary>
/// <param name="Path">原服务器路径</param>
/// <param name="Path_syp">生成的带水印的路径</param>
/// <param name="Path_sypf">水印路径</param>
public static void AddWaterPic(string Path, string Path_syp, string Path_sypf)
{
System.Drawing.Image image = System.Drawing.Image.FromFile(Path);
System.Drawing.Image copyImage = System.Drawing.Image.FromFile(Path_sypf);
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(image);
g.DrawImage(copyImage, new System.Drawing.Rectangle(image.Width - copyImage.Width, image.Height - copyImage.Height, copyImage.Width, copyImage.Height), 0, 0, copyImage.Width, copyImage.Height, System.Drawing.GraphicsUnit.Pixel);
g.Dispose();
image.Save(Path_syp);
image.Dispose();
}
}
}
å¦ä½ç¼è¯Windowsä¸çOpenOCD
ãOpenOCDä»ç»ã
OpenOCD为åµå ¥å¼ç®æ ç³»ç»æä¾ä¸ä¸ªè°è¯ï¼å¨çº¿ç¼ç¨åJTAGè¾¹çæ«ææµè¯çå·¥å ·ãæ¯æWigglerï¼åºäºFTçJTAGçé¢çä¸äºè°è¯å¨ãç®æ è¯çæ¯æARM7,ARM9, ARM, ARMåCortexçæ ¸å¿çè¯çã并æä¾ä¸ä¸ªGDB Serveræ¥å£ã
ãOpenOCDçç¼è¯åå®è£ ã
1. å¦ææ¯Windowså¹³å°çè¯ï¼éè¦å å®è£ Cygwinç¯å¢ï¼æ³¨æä¸å®è¦éæ©å®è£ 以ä¸å¼åå ï¼
- autoconf: Wrapper scripts for autoconf commands
- automake: Wrapper scripts for automake and aclocals
- gcc: C compiler upgrade helper
- make: The GNU version og the 'make' utility
- subversion: A version control system
(å¯ä»¥å®å ¨å®è£ ï¼å ç¨5Gå¤ç空é´ï¼éè¦ä¸è½½Mçæ件)ã
2. ä¸è½½OpenOCDçSVNæºä»£ç ï¼æå¼Cygwinå½ä»¤è¡çé¢ï¼æ§è¡å¦ä¸çå½ä»¤ï¼
mkdir /home/openocd
cd /home/openocd
svn checkout svn://svn.berlios.de/openocd/trunkãææ¯
svn checkout bined on interfaces or targets that can't set TRST/SRST separately
reset_config trst_and_srst srst_pulls_trst
#LPCs need reset pulled while RTCK is low. 0 to activate JTAG, power-on reset is not enough
jtag_reset 1 1
jtag_reset 0 0
#jtag scan chain
jtag_device 4 0x1 0xf 0xe
target arm7tdmi little 0 arm7tdmi-s_r4
[new_target_name] configure -event reset-init {
# Force target into ARM state
soft_reset_halt
#do not remap 0x-0x to anything but the flash
mwb 0xEFC 0x
}
working_area 0 0x 0x nobackup
#flash bank lpc <base> <size> 0 0 <target#> <variant>
flash bank lpc 0x0 0x7d 0 0 0 lpc_v2
ãOpenOCDçæµè¯ã
æå¼Cygwinå½ä»¤è¡çé¢ï¼æ§è¡å½ä»¤ï¼
openocd -f openocd.cfg
以ä¸æ¯æçè¿è¡æªå¾ï¼
ãIARçé ç½®ã
å¨é¡¹ç®é项çDebugä¸çsetup页éï¼éæ©GDB Serverï¼
å¦æ代ç éè¦ä¸è½½å°flashä¸è¿è¡ï¼Download页ééæ©Use flash loaderï¼å¨plugin页éï¼å¯ä»¥å»æstack以æé«é度ã
å¨ä¸é¢çGDB Serverä¸ï¼TCP/IP address or hostnameä¸æ·»localhostã
ä¹åå°±å¯ä»¥æè°è¯æé®å¼å§è°è¯äºã
Opencv中的两种去畸变函数
在探讨 OpenCV 中的两种去畸变函数前,我们首先需要了解畸变校正和损失有效像素原理。在相机标定后,OpenCV 提供了两种主要方法来处理图像畸变:直接使用 cv::undistort() 函数得到去畸变图像,或通过 cv::getOptimalNewCameraMatrix() 获取新的矩阵,再利用 cv::initUndistortRectifyMap() 和 cv::remap() 函数映射原图至新图。
在比较两种方法的差异之前,让我们先对 getOptimalNewCameraMatrix() 函数进行简要介绍。java图形设计源码函数参数 alpha 对结果影响重大。当 alpha 为 0 时,生成的矩阵为内矩阵,即不包含任何黑色边框的图像大小,以此重新计算内参。如果 alpha 为 1,iw源码包下载则生成的矩阵为外矩阵,等同于原图大小。当 alpha 在 0 到 1 之间时,将按照比例重新计算内参。内矩阵等同于不含任何黑色边框的图幅大小,而外矩阵等同于原图大小。lnmp安装zabbix源码
深入探究 getOptimalNewCameraMatrix() 的实现过程,我们发现其 inner 和 outer 矩阵的生成与原始内参和畸变系数之间存在密切联系。通过在 icvGetRectangles() 函数中生成 9x9 个点,并对这些点进行去畸变转换,我们得到外围矩阵 oX0, oY0, oX1, oY1 及内围矩阵。这些矩阵的标价线公式源码生成有助于理解原始图像的畸变情况。
在实际应用中,如处理 Ladybug 相机时,可以自动获得去畸变图像,但通常包含黑色边框。为了去除这些边框,尝试将 alpha 设为 0 来得到去黑边图像。然而,当只提供相机内参而无畸变系数时,使用空畸变系数会导致内参不变。通过深入研究源码,我们发现,在畸变系数为空时,inner 与 outer 矩阵大小相同,导致 fx, fy, cx, cy 参数保持不变。因此,为了获得理想的去黑边图像,需要手动截取可视范围,并基于新左上角重新计算 cx, cy,从而得到新的去黑边图像和对应的新相机内参。
综上所述,理解 OpenCV 中的两种去畸变方法有助于在实际项目中灵活选择合适的处理策略。通过分析内参、畸变系数和生成的矩阵,可以更有效地处理和优化图像,满足不同应用需求。