所以我基本上要做的是将图像中的像素转换为我想要的颜色,我在openCV中找不到任何东西,我想出的唯一方法是:
for (int i = 0; i < image.cols(); i++) {
for (int j = 0; j < image.rows(); j++) {
double[] data = image.get(i, j);
data[0] = 255;
data[1] = 255;
data[2] = 255;
image.put(i, j, data);
}
}
Utils.matToBitmap(image, bmp);
return bmp;;
试图在java中模仿这个c++ code,但它不起作用
答案 0 :(得分:0)
好的,发现为什么它不起作用,我应该写:
Public Function RGBtoDecimal(red As Integer, green As Integer, blue As Integer) As Long
Dim dec As Long = 0
Dim n, r As Integer
'write each colour as base 16
'blue first, starting with smallest power of 16 right to left
n = blue
Dim j As Integer = 0
For i As Integer = 0 To 1
r = CInt(Math.Round(16 * ((n / 16) - Int(n / 16))))
n = CInt(Int(n / 16))
dec = CLng(dec + (r * (16 ^ j)))
j += 1
Next
'green
n = green
For i As Integer = 0 To 1
r = CInt(Math.Round(16 * ((n / 16) - Int(n / 16))))
n = CInt(Int(n / 16))
dec = CLng(dec + (r * (16 ^ j)))
j += 1
Next
'red
n = red
For i As Integer = 0 To 1
r = CInt(Math.Round(16 * ((n / 16) - Int(n / 16))))
n = CInt(Int(n / 16))
dec = CLng(dec + (r * (16 ^ j)))
j += 1
Next
Return dec
End Function
而不是:
for (int i = 0; i < image.height(); i++) {
for (int j = 0; j < image.width(); j++) {