使用JavaCV我尝试将不同的颜色应用于输入范围内两个数字之间的区域。请参阅以下代码,了解它应如何工作的示例:
Mat mask = new Mat();
inRange(intensity, new Scalar(0.0), new Scalar(0.3), mask);
image.setTo(new Scalar(255.0, 0.0, 0.0, 1.0), mask);
我无法编译该代码,因为JavaCV似乎期望inRange和setTo中都有Mat
而不是Scalar
对象,请参阅此处的定义:
@Namespace("cv") public static native void inRange(@ByVal Mat src,
@ByVal Mat lowerb, @ByVal Mat upperb, @ByVal Mat dst);
在OpenCV文档Scalar
中应该没有问题,而不是Mat
。有没有办法将Scalar
转换为Mat
,这样可行?
我注意到我可以使用cvInRangeS
代替inRange
,但我无法找到与setTo
功能等效的内容。
答案 0 :(得分:0)
在使用格式inRange
Mat
OpenCV Error: Sizes of input arguments do not match (The lower bounary is neither an array of the same size and same type as src, nor a scalar)
进行调用时,您应该收到的错误是Mat
,或者其他内容(请注意拼写错误)。
如果您想将Scalar
用作Mat
,则可以使用double[]
或Scalar
对象初始化new Mat(new double[]{255, 255, 255, 0})
。例如:private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
{
//frame
e.Graphics.DrawRectangle(Pens.Black, 30, 30, 757, 1080);
//rows
e.Graphics.DrawLine(Pens.Black, 30, 184, 787, 184);
e.Graphics.DrawLine(Pens.Black, 30, 338, 787, 338);
e.Graphics.DrawLine(Pens.Black, 30, 492, 787, 492);
e.Graphics.DrawLine(Pens.Black, 30, 646, 787, 646);
e.Graphics.DrawLine(Pens.Black, 30, 800, 787, 800);
e.Graphics.DrawLine(Pens.Black, 30, 955, 787, 955);
//columns
e.Graphics.DrawLine(Pens.Black, 282, 30, 282, 1110);
e.Graphics.DrawLine(Pens.Black, 534, 30, 534, 1110);
int rows_loc = 35;
int cols_loc = 70;
int lable_index = 0;
foreach (ListViewItem item in listView1.Items)
{
for (int quantity = 1; quantity < (Convert.ToInt32(item.SubItems[1].Text) + 1); quantity++)
{
Font font = new System.Drawing.Font("Arial", 16);
SolidBrush black = new SolidBrush(Color.Black);
Zen.Barcode.Code128BarcodeDraw barcode1 = Zen.Barcode.BarcodeDrawFactory.Code128WithChecksum;
Image barcode_image = barcode1.Draw(item.SubItems[2].Text, 20);
e.Graphics.DrawImage(barcode_image, 40f + cols_loc, 29f + rows_loc);
e.Graphics.DrawString(item.Text, font, black, 60f + cols_loc, 0f + rows_loc);
lable_index++;
row_index = (int)(lable_index / 3);
col_index = lable_index % 3;
rows_loc = 35 + ((row_index) * 155);
cols_loc = 70 + (250 * col_index);
if (rows_loc >= e.PageSettings.PrintableArea.Height)
{
e.HasMorePages = true;
rows_loc = 35;
return;
}
else
{
e.HasMorePages = false;
}
}
}
}
。