GVKun编程网logo

binary,varbinary,image的区别(binary和varbinary)

14

本文的目的是介绍binary,varbinary,image的区别的详细情况,特别关注binary和varbinary的相关信息。我们将通过专业的研究、有关数据的分析等多种方式,为您呈现一个全面的了解

本文的目的是介绍binary,varbinary,image的区别的详细情况,特别关注binary和varbinary的相关信息。我们将通过专业的研究、有关数据的分析等多种方式,为您呈现一个全面的了解binary,varbinary,image的区别的机会,同时也不会遗漏关于.net – SQL Server Varbinary(max):从varbinary字段中选择一个字节子集、c# – 如何将图像存储到varbinary(max)列?、C#二进制读写BinaryReader、BinaryWriter、BinaryFormatter、edu.wpi.first.wpilibj.image.BinaryImage的实例源码的知识。

本文目录一览:

binary,varbinary,image的区别(binary和varbinary)

binary,varbinary,image的区别(binary和varbinary)

binary

固定长度的二进制数据,其最大长度为 8,000 个字节。

varbinary

可变长度的二进制数据,其最大长度为 8,000 个字节。

image

可变长度的二进制数据,其最大长度为 2^31 - 1 (2,147,483,647) 个字节

在 Microsoft sql Server 的未来版本中将删除 ntext、text 和 image 数据类型。请避免在新开发工作中使用这些数据类型,
并考虑修改当前使用这些数据类型的应用程序。请改用 nvarchar(max)、varchar(max) 和 varbinary(max)。

ntext 长度可变的 Unicode 数据,最大长度为 2^30 - 1 (1,073,741,823) 个字符。存储大小是所输入字符个数的两倍(以字节为单位)。ntext 的 sql 2003 同义词为 national text。text 服务器代码页中长度可变的非 Unicode 数据,最大长度为 2^31-1 (2,647) 个字符。当服务器代码页使用双字节字符时,存储仍是 2,647 字节。根据字符串,存储大小可能小于 2,647 字节。image 长度可变的二进制数据,从 0 到 2^31-1 (2,647) 个字节。--------------------- 作者:fox123871 来源:CSDN 原文:https://blog.csdn.net/fox123871/article/details/7667154 版权声明:本文为博主原创文章,转载请附上博文链接!

.net – SQL Server Varbinary(max):从varbinary字段中选择一个字节子集

.net – SQL Server Varbinary(max):从varbinary字段中选择一个字节子集

在sql Server 2008中,从varbinary(MAX)字段(不使用FileStreams)读取部分二进制数据的最有效方式是什么?

当向数据库中写入数据时,T-sql中有可用的VarBinary.Write()函数,允许字节递增地写入字段,但是似乎没有类似的功能可用于读取数据.

我知道.Net中的DataReader.GetBytes()方法,它将只选择您要求的字节,但是会带来性能开销吗?即,sqlserver中的select将会读取数据库中的所有字节,然后给出getBytes()方法所有这些字节,以便从它们请求的字节的子集?

感谢任何帮助.

解决方法

您使用 SUBSTRING.这从服务器上的varbinary数据中读取一段代码段,并且只将代码段返回给客户端.

c# – 如何将图像存储到varbinary(max)列?

c# – 如何将图像存储到varbinary(max)列?

我在将一个 Image插入sql server 2008时遇到了这个以下的sql异常.

Implicit conversion from data type nvarchar to varbinary(max) is not
allowed. Use the CONVERT function to run this query

在数据库中,Image列的数据类型是Varbinary(MAX).

编辑

代码解除了评论

paramaters.Add(getParam("@imageFilePath",DbType.AnsiString,imageFilePath));

解决方法

使用它将文件读入字节数组:
// Old fashioned way
    public static byte[] ReadFile(string filePath)
    {
        byte[] buffer;
        FileStream fileStream = new FileStream(filePath,FileMode.Open,FileAccess.Read);
        try
        {
            int length = (int)fileStream.Length;  // get file length
            buffer = new byte[length];            // create buffer
            int count;                            // actual number of bytes read
            int sum = 0;                          // total number of bytes read

            // read until Read method returns 0 (end of the stream has been reached)
            while ((count = fileStream.Read(buffer,sum,length - sum)) > 0)
                sum += count;  // sum is a buffer offset for next reading
        }
        finally
        {
            fileStream.Close();
        }
        return buffer;
    }

要么

// Thanks Magnus!
    byte[] data = System.IO.File.ReadAllBytes(filePath);

然后使用此保存图像数据(我使用的图像类“实例”包含我在instance.Data中的图像信息和字节数组):

using(sqlCommand cm = new sqlCommand("SaveImage",connection,transaction)){
       cm.CommandType = CommandType.StoredProcedure;
       cm.Parameters.Add(new sqlParameter("@Id",sqlDbType.Int,ParameterDirection.InputOutput,false,10,"Id",DaTarowVersion.Current,(sqlInt32)instance.Id));
       cm.Parameters.Add(new sqlParameter("@Title",sqlDbType.NVarChar,50,ParameterDirection.Input,"Title",(sqlString)instance.Title));
       if (instance.Data.Length > 0)
       {
           cm.Parameters.Add(new sqlParameter("@Data",sqlDbType.VarBinary,instance.Data.Length,"Data",(sqlBinary)instance.Data));
       }
       else
       {
           cm.Parameters.Add(new sqlParameter("@Data",dbnull.Value));                    
       }

       cm.ExecuteNonQuery();
   )

这是一个示例存储过程:

CREATE PROCEDURE SaveImage
(
@Id int OUTPUT,@Title nvarchar(50),@Data varbinary(MAX)
)
AS
SET NOCOUNT ON
SET XACT_ABORT ON

IF @Id IS NULL OR @Id <= 0
BEGIN
SELECT @Id = ISNULL(MAX([Id]),0) + 1 FROM [dbo].[Images]
END

INSERT INTO [dbo].[Images] (
[Id],[Title],[Data]
) VALUES (
@Id,@Title,@Data
)

C#二进制读写BinaryReader、BinaryWriter、BinaryFormatter

C#二进制读写BinaryReader、BinaryWriter、BinaryFormatter

一、二进制读写类:

1、BinaryReader/BinaryWriter:二进制读写

  • BinaryReader:用特定的编码将基元数据类型读作二进制值。
  • BinaryWriter:以二进制形式将基元类型写入流,并支持用特定的编码写入字符串。

2、XmlReader/XmlWriter :XML读写

见:C#使⽤XmlReader和XmlWriter操作XML⽂件

二、BinaryReader/BinaryWriter

读写流的基元数据类型。可以操作图像、压缩文件等二进制文件。也可以是MemoryStream等。

不需要一个字节一个字节进行操作,可以是2个、4个、或8个字节这样操作。

可以将一个字符或数字按指定数量的字节进行写入。

1、写入:

using (BinaryWriter writer = new BinaryWriter(File.Open(fileName, FileMode.Create)))
{
    writer.Write(1.250F);
    writer.Write(@"c:\Temp");
    writer.Write(10);
    writer.Write(true);
}

Response.BinaryWrite()方法输出二进制图像

FileStream fs = new FileStream(Server.MapPath("未命名.jpg"), FileMode.Open);//将图片文件存在文件流中
long fslength = fs.Length;//流长度
byte[] b=new byte[(int)fslength];//定义二进制数组
fs.Read(b, 0, (int)fslength);//将流中字节写入二进制数组中
fs.Close();//关闭流
Response.ContentType = "image/jpg";//没有这个会出现乱码
Response.BinaryWrite(b);//将图片输出在页面

2、读取:

每次读取都回提升流中的当前位置相应数量的字节。

下面的代码示例演示了如何存储和检索文件中的应用程序设置。

const string fileName = "AppSettings.dat";
float aspectRatio;
string tempDirectory;
int autoSaveTime;
bool showStatusBar;

if (File.Exists(fileName))
{
    using (BinaryReader reader = new BinaryReader(File.Open(fileName, FileMode.Open)))
    {
        aspectRatio = reader.ReadSingle();
        tempDirectory = reader.ReadString();
        autoSaveTime = reader.ReadInt32();
        showStatusBar = reader.ReadBoolean();
    }

    Console.WriteLine("Aspect ratio set to: " + aspectRatio);
    Console.WriteLine("Temp directory is: " + tempDirectory);
    Console.WriteLine("Auto save time set to: " + autoSaveTime);
    Console.WriteLine("Show status bar: " + showStatusBar);
}

BinaryReader读取图片:

using (FileStream fs = new FileStream("1.jpg", FileMode.Open, FileAccess.Read))
{
    //将图片以文件流的形式进行保存
    using (BinaryReader br = new BinaryReader(fs))
    {
        byte[] imgBytesIn = br.ReadBytes((int)fs.Length); //将流读入到字节数组中
        br.Close();
    }
}

三、以二进制格式序列化对象BinaryFormatter

1、SoapFormatter(用于HTTP中)和BinaryFormatter(用于TCP中)类实现了IFormatter接口 (由继承IRemotingFormatter,支持远程过程调用 (Rpc))

  • Deserialize(Stream) 反序列化所提供流中的数据并重新组成对象图形。
  • Serialize(Stream, Object) 将对象或具有给定根的对象图形序列化为所提供的流。

XML序列化见:https://www.jb51.net/article/250477.htm

2、举例:

[Serializable]
public class Product //实体类
{
    public long Id;
    [NonSerialized]//标识不序列化此成员Name
    public string Name;
    public Product(long Id, string Name)
    {
        this.Id = Id;
        this.Name = Name;
    }
}

static void Main()
{
    //序列化(对象保存到文件)
    List<Product> Products = new List<Product> {
        new Product(1,"a"),new Product(2,"b")
    };

    FileStream fs = new FileStream("DataFile.dat", FileMode.Create);
    IFormatter formatter = new BinaryFormatter();
    formatter.Serialize(fs, Products);
    fs.Close();

    //反序列化(文件内容转成对象)
    FileStream fs1 = new FileStream("DataFile.dat", FileMode.Open);
    BinaryFormatter formatter1 = new BinaryFormatter();
    List<Product> addresses = (List<Product>)formatter1.Deserialize(fs1);
    fs1.Close();
    foreach (Product de in addresses)
    {
        Console.WriteLine("{0} lives at {1}.", de.Id, de.Name);
    }
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

您可能感兴趣的文章:
  • C# BinaryReader实现读取二进制文件
  • C# 进制转换的实现(二进制、十六进制、十进制互转)
  • C#中图片、二进制与字符串的相互转换方法
  • C#实现文件与二进制互转并存入数据库
  • C#读取二进制文件方法分析
  • c#二进制逆序方法详解
  • C# 图片与二进制转换的简单实例
  • C# 向二进制文件进行读写的操作方法
  • c# 以二进制读取文本文件

edu.wpi.first.wpilibj.image.BinaryImage的实例源码

edu.wpi.first.wpilibj.image.BinaryImage的实例源码

项目:2014CataBot    文件:ImagingUtils.java   
/**
 * Computes a score (0-100) comparing the aspect ratio to the ideal aspect
 * ratio for the target. This method uses the equivalent rectangle sides to
 * determine aspect ratio as it performs better as the target gets skewed by
 * moving to the left or right. The equivalent rectangle is the rectangle
 * with sides x and y where particle area= x*y and particle perimeter= 2x+2y
 *
 * @param image The image containing the particle to score,needed to
 * performa additional measurements
 * @param report The Particle Analysis Report for the particle,used for the
 * width,height,and particle number
 * @param outer Indicates whether the particle aspect ratio should be
 * compared to the ratio for the inner target or the outer
 * @return The aspect ratio score (0-100)
 */
public static double scoreAspectRatio(BinaryImage image,ParticleAnalysisReport report,int particleNumber,boolean outer) throws NIVisionException {
    double rectLong,rectShort,aspectRatio,idealAspectRatio;

    rectLong = NIVision.MeasureParticle(image.image,particleNumber,false,NIVision.MeasurementType.IMAQ_MT_EQUIVALENT_RECT_LONG_SIDE);
    rectShort = NIVision.MeasureParticle(image.image,NIVision.MeasurementType.IMAQ_MT_EQUIVALENT_RECT_SHORT_SIDE);
    //idealAspectRatio = outer ? (62/29) : (62/20); //Dimensions of goal opening + 4 inches on all 4 sides for reflective tape
    idealAspectRatio = outer ? (43 / 32) : (39 / 28);
    //Divide width by height to measure aspect ratio
    aspectRatio = report.boundingRectWidth / (double) report.boundingRectHeight;
    /*if(report.boundingRectWidth > report.boundingRectHeight){
     //particle is wider than it is tall,divide long by short
     aspectRatio = 100*(1-Math.abs((1-((rectLong/rectShort)/idealAspectRatio))));
     } else {
     //particle is taller than it is wide,divide short by long
     aspectRatio = 100*(1-Math.abs((1-((rectShort/rectLong)/idealAspectRatio))));
     }*/
    return aspectRatio;
    //return (Math.max(0,Math.min(aspectRatio,100.0)));       //force to be in range 0-100
}
项目:2014CataBot    文件:ImagingUtils.java   
/**
 * Computes a score based on the match between a template profile and the
 * particle profile in the X direction. This method uses the the column
 * averages and the profile defined at the top of the sample to look for the
 * solid vertical edges with a hollow center.
 *
 * @param image The image to use,should be the image before the convex hull
 * is performed
 * @param report The Particle Analysis Report for the particle
 *
 * @return The X Edge score (0-100)
 */
public static double scoreXEdge(BinaryImage image,ParticleAnalysisReport report) throws NIVisionException {
    double total = 0;
    Linearaverages averages;

    NIVision.Rect rect = new NIVision.Rect(report.boundingRectTop,report.boundingRectLeft,report.boundingRectHeight,report.boundingRectWidth);
    averages = NIVision.getLinearaverages(image.image,Linearaverages.LinearaveragesMode.IMAQ_COLUMN_AVERAGES,rect);
    float columnAverages[] = averages.getColumnAverages();
    for (int i = 0; i < (columnAverages.length); i++) {
        if (xMin[(i * (XMINSIZE - 1) / columnAverages.length)] < columnAverages[i]
                && columnAverages[i] < xMax[i * (XMAXSIZE - 1) / columnAverages.length]) {
            totaL++;
        }
    }
    total = 100 * total / (columnAverages.length);
    return total;
}
项目:2014CataBot    文件:ImagingUtils.java   
/**
 * Computes a score based on the match between a template profile and the
 * particle profile in the Y direction. This method uses the the row
 * averages and the profile defined at the top of the sample to look for the
 * solid horizontal edges with a hollow center
 *
 * @param image The image to use,should be the image before the convex hull
 * is performed
 * @param report The Particle Analysis Report for the particle
 *
 * @return The Y Edge score (0-100)
 *
 */
public static double scoreYEdge(BinaryImage image,Linearaverages.LinearaveragesMode.IMAQ_ROW_AVERAGES,rect);
    float rowAverages[] = averages.getRowAverages();
    for (int i = 0; i < (rowAverages.length); i++) {
        if (yMin[(i * (YMINSIZE - 1) / rowAverages.length)] < rowAverages[i]
                && rowAverages[i] < yMax[i * (YMAXSIZE - 1) / rowAverages.length]) {
            totaL++;
        }
    }
    total = 100 * total / (rowAverages.length);
    return total;
}
项目:Aerial-Assist    文件:AxisCameraM1101.java   
/**
 * Computes a score (0-100) comparing the aspect ratio to the ideal aspect
 * ratio for the target. This method uses the equivalent rectangle sides to
 * determine aspect ratio as it performs better as the target gets skewed by
 * moving to the left or right. The equivalent rectangle is the rectangle
 * with sides x and y where particle area,xy and particle perimeter,2x+2y
 *
 * @param image The image containing the particle to score,needed to
 * perform additional measurements
 * @param report The Particle Analysis Report for the particle,and particle number
 * @param outer Indicates whether the particle aspect ratio should be
 * compared to the ratio for the inner target or the outer
 * @return The aspect ratio score (0-100)
 */
private double scoreAspectRatio(BinaryImage image,ParticleAnalysisReport 
        report,boolean vertical) throws 
        NIVisionException {

    double rectLong,MeasurementType.IMAQ_MT_EQUIVALENT_RECT_LONG_SIDE);
    rectShort = NIVision.MeasureParticle(image.image,MeasurementType.IMAQ_MT_EQUIVALENT_RECT_SHORT_SIDE);
    idealAspectRatio = vertical ? (4.0 / 32) : (23.5 / 4);

    if (report.boundingRectWidth > report.boundingRectHeight) {
        aspectRatio = ratioToscore((rectLong / rectShort)/idealAspectRatio);
    } else {
        aspectRatio = ratioToscore((rectShort / rectLong)/idealAspectRatio);
    }
    return aspectRatio;
}
项目:2014RobotCode    文件:CameraDetection.java   
public double scoreAspectRatio(BinaryImage image,boolean vertical) throws NIVisionException
   {
       double rectLong,idealAspectRatio;

       rectLong = NIVision.MeasureParticle(image.image,NIVision.MeasurementType.IMAQ_MT_EQUIVALENT_RECT_LONG_SIDE);
       rectShort = NIVision.MeasureParticle(image.image,NIVision.MeasurementType.IMAQ_MT_EQUIVALENT_RECT_SHORT_SIDE);
       idealAspectRatio = vertical ? (4.0/32) : (23.5/4);   //Vertical reflector 4" wide x 32" tall,horizontal 23.5" wide x 4" tall

       //Divide width by height to measure aspect ratio
       if(report.boundingRectWidth > report.boundingRectHeight){
           //particle is wider than it is tall,divide long by short
           aspectRatio = ratioToscore((rectLong/rectShort)/idealAspectRatio);
       } else {
           //particle is taller than it is wide,divide short by long
           aspectRatio = ratioToscore((rectShort/rectLong)/idealAspectRatio);
       }
return aspectRatio;
   }
项目:649code2014    文件:HottargetVision.java   
/**
 * Computes a score (0-100) comparing the aspect ratio to the ideal aspect
 * ratio for the target. This method uses the equivalent rectangle sides to
 * determine aspect ratio as it performs better as the target gets skewed by
 * moving to the left or right. The equivalent rectangle is the rectangle
 * with sides x and y where particle area= x*y and particle perimeter= 2x+2y
 *
 * @param image The image containing the particle to score,and particle number
 * @param outer Indicates whether the particle aspect ratio should be
 * compared to the ratio for the inner target or the outer
 * @return The aspect ratio score (0-100)
 */
private static double scoreAspectRatio(BinaryImage image,boolean vertical) throws NIVisionException {
    double rectLong,NIVision.MeasurementType.IMAQ_MT_EQUIVALENT_RECT_SHORT_SIDE);
    idealAspectRatio = vertical ? (4.0 / 32) : (23.5 / 4);  //Vertical reflector 4" wide x 32" tall,horizontal 23.5" wide x 4" tall

    //Divide width by height to measure aspect ratio
    if (report.boundingRectWidth > report.boundingRectHeight) {
        //particle is wider than it is tall,divide long by short
        aspectRatio = ratioToscore((rectLong / rectShort) / idealAspectRatio);
    } else {
        //particle is taller than it is wide,divide short by long
        aspectRatio = ratioToscore((rectShort / rectLong) / idealAspectRatio);
    }
    return aspectRatio;
}
项目:FRCTesting    文件:ImageUtils.java   
/**
 * Computes a score (0-100) comparing the aspect ratio to the ideal aspect
 * ratio for the target. This method uses the equivalent rectangle sides to
 * determine aspect ratio as it performs better as the target gets skewed by
 * moving to the left or right. The equivalent rectangle is the rectangle
 * with sides x and y where particle area= x*y and particle perimeter= 2x+2y
 *
 * @param image The image containing the particle to score,100.0)));       //force to be in range 0-100
}
项目:FRCTesting    文件:ImageUtils.java   
/**
 * Computes a score based on the match between a template profile and the
 * particle profile in the X direction. This method uses the the column
 * averages and the profile defined at the top of the sample to look for the
 * solid vertical edges with a hollow center.
 *
 * @param image The image to use,rect);
    float columnAverages[] = averages.getColumnAverages();
    for (int i = 0; i < (columnAverages.length); i++) {
        if (xMin[(i * (XMINSIZE - 1) / columnAverages.length)] < columnAverages[i]
                && columnAverages[i] < xMax[i * (XMAXSIZE - 1) / columnAverages.length]) {
            totaL++;
        }
    }
    total = 100 * total / (columnAverages.length);
    return total;
}
项目:FRCTesting    文件:ImageUtils.java   
/**
 * Computes a score based on the match between a template profile and the
 * particle profile in the Y direction. This method uses the the row
 * averages and the profile defined at the top of the sample to look for the
 * solid horizontal edges with a hollow center
 *
 * @param image The image to use,rect);
    float rowAverages[] = averages.getRowAverages();
    for (int i = 0; i < (rowAverages.length); i++) {
        if (yMin[(i * (YMINSIZE - 1) / rowAverages.length)] < rowAverages[i]
                && rowAverages[i] < yMax[i * (YMAXSIZE - 1) / rowAverages.length]) {
            totaL++;
        }
    }
    total = 100 * total / (rowAverages.length);
    return total;
}
项目:2014_software    文件:HotGoalDetector.java   
public double scoreAspectRatio(BinaryImage image,boolean vertical) throws NIVisionException
{
    double rectLong,horizontal 23.5" wide x 4" tall

    if (report.boundingRectWidth > report.boundingRectHeight)
    {
        aspectRatio = ratioToscore((rectLong / rectShort) / idealAspectRatio);
    }
    else
    {
        aspectRatio = ratioToscore((rectShort / rectLong) / idealAspectRatio);
    }
    return aspectRatio;
}
项目:2014_software    文件:HotGoalDetector.java   
public double scoreAspectRatioOnRotatedImage(BinaryImage image,NIVision.MeasurementType.IMAQ_MT_EQUIVALENT_RECT_SHORT_SIDE);
    idealAspectRatio = vertical ? (32.0 / 4) : (4/23.5);    //Vertical reflector 4" wide x 32" tall,horizontal 23.5" wide x 4" tall

    if (report.boundingRectWidth > report.boundingRectHeight)
    {
        aspectRatio = ratioToscore((rectLong / rectShort) / idealAspectRatio);
    }
    else
    {
        aspectRatio = ratioToscore((rectShort / rectLong) / idealAspectRatio);
    }
    return aspectRatio;
}
项目:FRC623Robot2014    文件:VisionController.java   
/**
 * Computes a score (0-100) comparing the aspect ratio to the ideal aspect
 * ratio for the target. This method uses the equivalent rectangle sides to
 * determine aspect ratio as it performs better as the target gets skewed by
 * moving to the left or right. The equivalent rectangle is the rectangle
 * with sides x and y where particle area= x*y and particle perimeter= 2x+2y
 *
 * @param image The image containing the particle to score,divide short by long
        aspectRatio = ratioToscore((rectShort / rectLong) / idealAspectRatio);
    }
    return aspectRatio;
}
项目:2013ultimate-ascent    文件:GRTVisionTracker.java   
/**
 * Computes a score (0-100) comparing the aspect ratio to the ideal aspect ratio for the target. This method uses
 * the equivalent rectangle sides to determine aspect ratio as it performs better as the target gets skewed by moving
 * to the left or right. The equivalent rectangle is the rectangle with sides x and y where particle area= x*y
 * and particle perimeter= 2x+2y
 * 
 * @param image The image containing the particle to score,needed to performa additional measurements
 * @param report The Particle Analysis Report for the particle,used for the width,and particle number
 * @param outer Indicates whether the particle aspect ratio should be compared to the ratio for the inner target or the outer
 * @return The aspect ratio score (0-100)
 */
public double scoreAspectRatio(BinaryImage image,boolean outer) throws NIVisionException
{
    double rectLong,NIVision.MeasurementType.IMAQ_MT_EQUIVALENT_RECT_SHORT_SIDE);
    //idealAspectRatio = outer ? (62/29) : (62/20); //Dimensions of goal opening + 4 inches on all 4 sides for reflective tape

    //yonatan - change back
    idealAspectRatio = outer ? (62/29) : (62/40);   //Dimensions of goal opening + 4 inches on all 4 sides for reflective tape

    //Divide width by height to measure aspect ratio
    if(report.boundingRectWidth > report.boundingRectHeight){
        //particle is wider than it is tall,divide long by short
        aspectRatio = 100*(1-Math.abs((1-((rectLong/rectShort)/idealAspectRatio))));
    } else {
        //particle is taller than it is wide,divide short by long
        aspectRatio = 100*(1-Math.abs((1-((rectShort/rectLong)/idealAspectRatio))));
    }
    return (Math.max(0,100.0)));     //force to be in range 0-100
}
项目:2013ultimate-ascent    文件:GRTVisionTracker.java   
/**
 * Computes a score based on the match between a template profile and the particle profile in the X direction. This method uses the
 * the column averages and the profile defined at the top of the sample to look for the solid vertical edges with
 * a hollow center.
 * 
 * @param image The image to use,should be the image before the convex hull is performed
 * @param report The Particle Analysis Report for the particle
 * 
 * @return The X Edge score (0-100)
 */
public double scoreXEdge(BinaryImage image,ParticleAnalysisReport report) throws NIVisionException
{
    double total = 0;
    Linearaverages averages;

    NIVision.Rect rect = new NIVision.Rect(report.boundingRectTop,rect);
    float columnAverages[] = averages.getColumnAverages();
    for(int i=0; i < (columnAverages.length); i++){
        if(xMin[(i*(XMINSIZE-1)/columnAverages.length)] < columnAverages[i] 
                && columnAverages[i] < xMax[i*(XMAXSIZE-1)/columnAverages.length]){
            totaL++;
                }
    }
    total = 100*total/(columnAverages.length);
    return total;
}
项目:2013ultimate-ascent    文件:GRTVisionTracker.java   
/**
 * Computes a score based on the match between a template profile and the particle profile in the Y direction. This method uses the
 * the row averages and the profile defined at the top of the sample to look for the solid horizontal edges with
 * a hollow center
 * 
 * @param image The image to use,should be the image before the convex hull is performed
 * @param report The Particle Analysis Report for the particle
 * 
 * @return The Y Edge score (0-100)
 *
 */
public double scoreYEdge(BinaryImage image,rect);
    float rowAverages[] = averages.getRowAverages();
    for(int i=0; i < (rowAverages.length); i++){
        if(yMin[(i*(YMINSIZE-1)/rowAverages.length)] < rowAverages[i] 
                && rowAverages[i] < yMax[i*(YMAXSIZE-1)/rowAverages.length]){
            totaL++;
                }
    }
    total = 100*total/(rowAverages.length);
    return total;
}
项目:grtframeworkv7    文件:GRTVisionTracker.java   
/**
 * Computes a score (0-100) comparing the aspect ratio to the ideal aspect ratio for the target. This method uses
 * the equivalent rectangle sides to determine aspect ratio as it performs better as the target gets skewed by moving
 * to the left or right. The equivalent rectangle is the rectangle with sides x and y where particle area= x*y
 * and particle perimeter= 2x+2y
 * 
 * @param image The image containing the particle to score,100.0)));     //force to be in range 0-100
}
项目:grtframeworkv7    文件:GRTVisionTracker.java   
/**
 * Computes a score based on the match between a template profile and the particle profile in the X direction. This method uses the
 * the column averages and the profile defined at the top of the sample to look for the solid vertical edges with
 * a hollow center.
 * 
 * @param image The image to use,rect);
    float columnAverages[] = averages.getColumnAverages();
    for(int i=0; i < (columnAverages.length); i++){
        if(xMin[(i*(XMINSIZE-1)/columnAverages.length)] < columnAverages[i] 
                && columnAverages[i] < xMax[i*(XMAXSIZE-1)/columnAverages.length]){
            totaL++;
                }
    }
    total = 100*total/(columnAverages.length);
    return total;
}
项目:grtframeworkv7    文件:GRTVisionTracker.java   
/**
 * Computes a score based on the match between a template profile and the particle profile in the Y direction. This method uses the
 * the row averages and the profile defined at the top of the sample to look for the solid horizontal edges with
 * a hollow center
 * 
 * @param image The image to use,rect);
    float rowAverages[] = averages.getRowAverages();
    for(int i=0; i < (rowAverages.length); i++){
        if(yMin[(i*(YMINSIZE-1)/rowAverages.length)] < rowAverages[i] 
                && rowAverages[i] < yMax[i*(YMAXSIZE-1)/rowAverages.length]){
            totaL++;
                }
    }
    total = 100*total/(rowAverages.length);
    return total;
}
项目:Team_1482_2013    文件:vision.java   
/**
    * Computes a score (0-100) comparing the aspect ratio to the ideal aspect ratio for the target. This method uses
    * the equivalent rectangle sides to determine aspect ratio as it performs better as the target gets skewed by moving
    * to the left or right. The equivalent rectangle is the rectangle with sides x and y where particle area= x*y
    * and particle perimeter= 2x+2y
    * 
    * @param image The image containing the particle to score,needed to perform additional measurements
    * @param report The Particle Analysis Report for the particle,and particle number
    * @param outer  Indicates whether the particle aspect ratio should be compared to the ratio for the inner target or the outer
    * @return The aspect ratio score (0-100)
    */
   public double scoreAspectRatio(BinaryImage image,divide short by long
           aspectRatio = ratioToscore((rectShort/rectLong)/idealAspectRatio);
       }
return aspectRatio;
   }
项目:Aerial-Assist    文件:AxisCameraM1101.java   
/**
 * Computes the estimated distance to a target using the height of the
 * particle in the image. For more information and graphics showing the math
 * behind this approach see the Vision Processing section of the
 * ScreenStepsLive documentation.
 *
 * @param image The image to use for measuring the particle estimated
 * rectangle.
 * @param report The particle analysis report for the particle.
 * @param outer True if the particle should be treated as an outer target,* false to treat it as a center target.
 * @return The estimated distance to the target in inches.
 */
private double computedistance(BinaryImage image,int particleNumber) throws NIVisionException {
    double rectLong,height;
    int targetHeight;

    rectLong = NIVision.MeasureParticle(image.image,MeasurementType.IMAQ_MT_EQUIVALENT_RECT_LONG_SIDE);
    height = Math.min(report.boundingRectHeight,rectLong);
    targetHeight = 32;

    return Y_IMAGE_RES * targetHeight / (height * 12 * 2 
            * Math.tan(VIEW_ANGLE * Math.PI / (180 * 2)));
}
项目:2014RobotCode    文件:CameraDetection.java   
double computedistance (BinaryImage image,int particleNumber) throws NIVisionException {
        double rectLong,height;
        int targetHeight;

        rectLong = NIVision.MeasureParticle(image.image,NIVision.MeasurementType.IMAQ_MT_EQUIVALENT_RECT_LONG_SIDE);
        //using the smaller of the estimated rectangle long side and the bounding rectangle height results in better performance
        //on skewed rectangles
        height = Math.min(report.boundingRectHeight,rectLong);
        targetHeight = 32;

        return Y_IMAGE_RES * targetHeight / (height * 12 * 2 * Math.tan(VIEW_ANGLE*Math.PI/(180*2)));
}
项目:2014_software    文件:HotGoalDetector.java   
double computedistance(BinaryImage image,int particleNumber) throws NIVisionException
{
    double rectLong,NIVision.MeasurementType.IMAQ_MT_EQUIVALENT_RECT_LONG_SIDE);

    height = Math.min(report.boundingRectHeight,rectLong);
    targetHeight = 32;

    return Y_IMAGE_RES * targetHeight / (height * 12 * 2 * Math.tan(VIEW_ANGLE * Math.PI / (180 * 2)));
}
项目:2014_software    文件:HotGoalDetector.java   
double computedistanceOnRotatedImage(BinaryImage image,NIVision.MeasurementType.IMAQ_MT_EQUIVALENT_RECT_LONG_SIDE);

    height = Math.min(report.boundingRectWidth,rectLong);
    targetHeight = 32;

    return X_IMAGE_RES * targetHeight / (height * 12 * 2 * Math.tan(HORIZ_VIEW_ANGLE * Math.PI / (180 * 2)));
}
项目:RobotCode2013    文件:Vision.java   
public VisionTarget [] processFrame() {
    if (enableVision) {
        lastFrame = System.currentTimeMillis();
        try {
            ColorImage image   = camera.getimage();
            BinaryImage bImage = image.thresholdRGB(
                    redLow,redHigh,greenLow,greenHigh,blueLow,blueHigh);
            BinaryImage fImage = bImage.particleFilter(cc);
            ParticleAnalysisReport [] report = fImage.getorderedParticleAnalysisReports();
            VisionTarget [] targets = new VisionTarget[report.length];
            for (int i = 0; i < report.length; i++) {
                double centerX = report[i].center_mass_x;
                double centerY = report[i].center_mass_y;
                double width = report[i].boundingRectWidth;
                double height = report[i].boundingRectHeight;
                int area = (int)report[i].particleArea;
                targets[i] = new VisionTarget(centerX,centerY,width,area);
            }
            frameProcess = System.currentTimeMillis() - lastFrame;
            image.free();
            bImage.free();
            fImage.free();
            return targets;
        } catch (AxisCameraException e) {
            System.out.println("No Image From Camera: ");
            frameProcess = System.currentTimeMillis() - lastFrame;
            return new VisionTarget[0];
        } catch (Exception ex) {
            System.out.println("Camera Exception Thrown: " + ex.getMessage());
            frameProcess = System.currentTimeMillis() - lastFrame;
            return new VisionTarget[0];
        }
    } else { // Vision is not enabled
        return new VisionTarget[0];
    }
}
项目:2013ultimate-ascent    文件:GRTVisionTracker.java   
/**
     * Computes the estimated distance to a target using the height of the particle in the image. For more information and graphics
     * showing the math behind this approach see the Vision Processing section of the ScreenStepsLive documentation.
     * 
     * @param image The image to use for measuring the particle estimated rectangle
     * @param report The Particle Analysis Report for the particle
     * @param outer True if the particle should be treated as an outer target,false to treat it as a center target
     * @return The estimated distance to the target in Inches.
     */
    double computedistance (BinaryImage image,boolean outer) throws NIVisionException {
        double rectShort,height;
        double targetWidth,targetHeight;


        rectShort = NIVision.MeasureParticle(image.image,NIVision.MeasurementType.IMAQ_MT_EQUIVALENT_RECT_SHORT_SIDE);
        //using the smaller of the estimated rectangle short side and the bounding rectangle height results in better performance
        //on skewed rectangles
        //height = Math.min(report.boundingRectHeight,rectShort);
        width = report.boundingRectWidth;
        height = report.boundingRectHeight;
        //targetHeight = outer ? 29 : 21;
        //changed by Yonatan Oren//
        //need to change this back to 29/21 for for real ultimate ascent//
        targetWidth = 16;
        targetHeight = 9.75;

////
//         System.out.println("rectShort: " + rectShort);
//         System.out.println("height: " + height);
//         System.out.println("boundingRectHeight: " + report.boundingRectHeight);

         //changed by Yonatan Oren//
        //return X_IMAGE_RES * targetHeight / (height * 12 * 2 * Math.tan(VIEW_ANGLE*Math.PI/(180*2)));
         //return 240.0 * targetWidth / (width * Math.tan(VIEW_ANGLE*Math.PI/(180*2)));
         return 360.0 * targetHeight / (height * Math.tan(VIEW_ANGLE*Math.PI/(180*2)));
         //4800 / 62 * tan(
    }
项目:grtframeworkv7    文件:GRTVisionTracker.java   
/**
     * Computes the estimated distance to a target using the height of the particle in the image. For more information and graphics
     * showing the math behind this approach see the Vision Processing section of the ScreenStepsLive documentation.
     * 
     * @param image The image to use for measuring the particle estimated rectangle
     * @param report The Particle Analysis Report for the particle
     * @param outer True if the particle should be treated as an outer target,rectShort);
        width = report.boundingRectWidth;
        height = report.boundingRectHeight;
        //targetHeight = outer ? 29 : 21;
        //changed by Yonatan Oren//
        //need to change this back to 29/21 for for real ultimate ascent//
        targetWidth = 16;
        targetHeight = 9.75;

////
//         System.out.println("rectShort: " + rectShort);
//         System.out.println("height: " + height);
//         System.out.println("boundingRectHeight: " + report.boundingRectHeight);

         //changed by Yonatan Oren//
        //return X_IMAGE_RES * targetHeight / (height * 12 * 2 * Math.tan(VIEW_ANGLE*Math.PI/(180*2)));
         //return 240.0 * targetWidth / (width * Math.tan(VIEW_ANGLE*Math.PI/(180*2)));
         return 360.0 * targetHeight / (height * Math.tan(VIEW_ANGLE*Math.PI/(180*2)));
         //4800 / 62 * tan(
    }
项目:Robot-Code-2013    文件:CameraSubsystem.java   
public BinaryImage getFilteredImage() throws Exception {
    ColorImage ci = getimage();
    bi = ci.thresholdRGB(RED_LOW,RED_HIGH,GREEN_LOW,GREEN_HIGH,BLUE_LOW,BLUE_HIGH);
    bi = bi.convexHull(false);
    bi = bi.removeSmallObjects(true,3);
    bi = bi.particleFilter(cc);
    ci.free();
    return bi;
}
项目:Team_1482_2013    文件:vision.java   
public BinaryImage getHSVimage(ColorImage image){
    try{
        this.HSVimage = image.thresholdHSV(92,196,19,100,30,100);
    } catch (NIVisionException ex) {
        ex.printstacktrace();
    }
    System.out.println("Processed HSV image");
    return this.HSVimage;
}
项目:Team_1482_2013    文件:vision.java   
public BinaryImage getRGBimage(ColorImage image) {
    try{
        this.RGBimage = image.thresholdRGB(0,150,145,230,120,225);
    } catch (NIVisionException ex) {
        ex.printstacktrace();
    }
    System.out.println("Processing RGB image");
    return this.RGBimage;
}
项目:Team_1482_2013    文件:vision.java   
/**
 * Computes the estimated distance to a target using the height of the particle in the image. For more information and graphics
 * showing the math behind this approach see the Vision Processing section of the ScreenStepsLive documentation.
 * 
 * @param image The image to use for measuring the particle estimated rectangle
 * @param report The Particle Analysis Report for the particle
 * @param outer True if the particle should be treated as an outer target,false to treat it as a center target
 * @return The estimated distance to the target in Inches.
 */
double computedistance (BinaryImage image,rectLong);
        targetHeight = 32;

        return Y_IMAGE_RES * targetHeight / (height * 12 * 2 * Math.tan(VIEW_ANGLE*Math.PI/(180*2)));
}
项目:2014CataBot    文件:ImagingUtils.java   
/**
 * Computes the estimated distance to a target using the height of the
 * particle in the image. For more information and graphics showing the math
 * behind this approach see the Vision Processing section of the
 * ScreenStepsLive documentation.
 *
 * @param image The image to use for measuring the particle estimated
 * rectangle
 * @param report The Particle Analysis Report for the particle
 * @param outer True if the particle should be treated as an outer target,* false to treat it as a center target
 * @return The estimated distance to the target in Inches.
 */
public static double computedistance(BinaryImage image,boolean outer) throws NIVisionException {
    double rectShort,height;
    int targetHeight;

    rectShort = NIVision.MeasureParticle(image.image,NIVision.MeasurementType.IMAQ_MT_EQUIVALENT_RECT_SHORT_SIDE);
    //using the smaller of the estimated rectangle short side and the bounding rectangle height results in better performance
    //on skewed rectangles
    height = Math.min(report.boundingRectHeight,rectShort);
    targetHeight = outer ? 29 : 21;

    return X_IMAGE_RES * targetHeight / (height * 12 * 2 * Math.tan(VIEW_ANGLE * Math.PI / (180 * 2)));
}
项目:649code2014    文件:HottargetVision.java   
/**
 * Computes the estimated distance to a target using the height of the
 * particle in the image. For more information and graphics showing the math
 * behind this approach see the Vision Processing section of the
 * ScreenStepsLive documentation.
 *
 * @param image The image to use for measuring the particle estimated
 * rectangle
 * @param report The Particle Analysis Report for the particle
 * @param outer True if the particle should be treated as an outer target,* false to treat it as a center target
 * @return The estimated distance to the target in Inches.
 */
private static double computedistance(BinaryImage image,NIVision.MeasurementType.IMAQ_MT_EQUIVALENT_RECT_LONG_SIDE);
    //using the smaller of the estimated rectangle long side and the bounding rectangle height results in better performance
    //on skewed rectangles
    height = Math.min(report.boundingRectHeight,rectLong);
    targetHeight = 32;

    return Y_IMAGE_RES * targetHeight / (height * 12 * 2 * Math.tan(VIEW_ANGLE * Math.PI / (180 * 2)));
}
项目:FRCTesting    文件:ImageUtils.java   
/**
 * Computes the estimated distance to a target using the height of the
 * particle in the image. For more information and graphics showing the math
 * behind this approach see the Vision Processing section of the
 * ScreenStepsLive documentation.
 *
 * @param image The image to use for measuring the particle estimated
 * rectangle
 * @param report The Particle Analysis Report for the particle
 * @param outer True if the particle should be treated as an outer target,rectShort);
    targetHeight = outer ? 29 : 21;

    return X_IMAGE_RES * targetHeight / (height * 12 * 2 * Math.tan(VIEW_ANGLE * Math.PI / (180 * 2)));
}
项目:FRC623Robot2014    文件:VisionController.java   
/**
 * Computes the estimated distance to a target using the height of the
 * particle in the image. For more information and graphics showing the math
 * behind this approach see the Vision Processing section of the
 * ScreenStepsLive documentation.
 *
 * @param image The image to use for measuring the particle estimated
 * rectangle
 * @param report The Particle Analysis Report for the particle
 * @param outer True if the particle should be treated as an outer target,* false to treat it as a center target
 * @return The estimated distance to the target in Inches.
 */
double computedistance(BinaryImage image,rectLong);
    targetHeight = 32;

    return Y_IMAGE_RES * targetHeight / (height * 12 * 2 * Math.tan(VIEW_ANGLE * Math.PI / (180 * 2)));
}

我们今天的关于binary,varbinary,image的区别binary和varbinary的分享已经告一段落,感谢您的关注,如果您想了解更多关于.net – SQL Server Varbinary(max):从varbinary字段中选择一个字节子集、c# – 如何将图像存储到varbinary(max)列?、C#二进制读写BinaryReader、BinaryWriter、BinaryFormatter、edu.wpi.first.wpilibj.image.BinaryImage的实例源码的相关信息,请在本站查询。

本文标签: