Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
imagej-elphel
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
3
Issues
3
List
Board
Labels
Milestones
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Elphel
imagej-elphel
Commits
fafa9362
Commit
fafa9362
authored
Jan 19, 2021
by
Andrey Filippov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
working on 14MP
parent
0246d531
Changes
5
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
11106 additions
and
10087 deletions
+11106
-10087
JP46_Reader_camera0.java
src/main/java/JP46_Reader_camera0.java
+71
-18
LaserPointer.java
...main/java/com/elphel/imagej/calibration/LaserPointer.java
+27
-35
MatchSimulatedPattern.java
.../com/elphel/imagej/calibration/MatchSimulatedPattern.java
+10867
-10014
CamerasInterface.java
.../elphel/imagej/calibration/hardware/CamerasInterface.java
+46
-7
JP46_Reader_camera.java
src/main/java/com/elphel/imagej/jp4/JP46_Reader_camera.java
+95
-13
No files found.
src/main/java/JP46_Reader_camera0.java
View file @
fafa9362
...
...
@@ -82,16 +82,21 @@ public class JP46_Reader_camera0 extends PlugInFrame implements ActionListener {
*
*/
private
static
final
long
serialVersionUID
=
390855361964415147L
;
public
static
int
[][]
BAYER_INDICES
=
{
{
0
,
1
,
2
,
3
},
{
1
,
0
,
3
,
2
},
{
2
,
3
,
0
,
1
},
{
3
,
2
,
1
,
0
}};
Panel
panel1
;
Panel
confpanel
;
Frame
instance
;
String
arg
;
static
File
dir
;
ImagejJp4Tiff
imagejJp4Tiff
=
new
ImagejJp4Tiff
();
static
File
dir
;
public
boolean
fix_bayer
=
true
;
// shift image (replacing last row/column) if (corrected for flips) BAYER_MODE != 0
public
String
camera_url
=
"http://192.168.0.236:8081/"
;
public
String
camera_img
=
"bimg"
;
public
String
camera_img_new
=
"towp/wait/bimg"
;
// will always wait for the next image (repetitive acquisitions get new images)
...
...
@@ -325,6 +330,7 @@ public class JP46_Reader_camera0 extends PlugInFrame implements ActionListener {
gd
.
addStringField
(
"Image (new): "
,
camera_img_new
,
20
);
gd
.
addStringField
(
"JP46 Parameters: "
,
camera_jp46settings
,
50
);
gd
.
addCheckbox
(
"Demux composite frame? "
,
demux
);
gd
.
addCheckbox
(
"Fix bayer (shift to standard GR/BG)? "
,
fix_bayer
);
gd
.
addCheckbox
(
"Silent? "
,
IS_SILENT
);
// gd.addCheckbox("JP4 (not JP46)? ", IS_JP4);
...
...
@@ -340,13 +346,14 @@ public class JP46_Reader_camera0 extends PlugInFrame implements ActionListener {
gd
.
showDialog
();
if
(
gd
.
wasCanceled
())
return
false
;
setTitle
(
gd
.
getNextString
());
setTitle
(
gd
.
getNextString
());
setURL
(
gd
.
getNextString
());
camera_img
=
gd
.
getNextString
();
camera_img_new
=
gd
.
getNextString
();
camera_jp46settings
=
gd
.
getNextString
();
demux
=
gd
.
getNextBoolean
();
IS_SILENT
=
gd
.
getNextBoolean
();
demux
=
gd
.
getNextBoolean
();
fix_bayer
=
gd
.
getNextBoolean
();
IS_SILENT
=
gd
.
getNextBoolean
();
return
true
;
}
public
ImagePlus
open
(
String
directory
,
String
fileName
,
String
arg
,
boolean
scale
)
{
...
...
@@ -523,6 +530,7 @@ public class JP46_Reader_camera0 extends PlugInFrame implements ActionListener {
double
[][]
rgammas
=
new
double
[
4
][];
double
min_gain
;
long
WOI_LEFT
,
WOI_WIDTH
,
WOI_TOP
,
WOI_HEIGHT
,
BAYER_MODE
,
DCM_HOR
,
DCM_VERT
,
BIN_HOR
,
BIN_VERT
;
BAYER_MODE
=
0
;
long
COLOR_MODE
=
0
;
long
FLIPH
=
0
;
long
FLIPV
=
0
;
...
...
@@ -794,35 +802,36 @@ public class JP46_Reader_camera0 extends PlugInFrame implements ActionListener {
}
}
/* apply gammas here */
int
[]
bayer_indices
=
BAYER_INDICES
[(
int
)
BAYER_MODE
];
if
(
MakerNote
!=
null
)
{
if
(
scale
)
{
for
(
y
=
0
;
y
<
16
;
y
+=
2
)
for
(
x
=
0
;
x
<
16
;
x
+=
2
)
{
i
=(
int
)
macroblock
[
y
][
x
];
if
(
i
<
0
)
i
=
0
;
else
if
(
i
>
255
)
i
=
255
;
macroblock
[
y
][
x
]=
(
float
)
(((
rgammas
[
1
][
i
])-
blacks256
[
1
])/
gains
[
1
]);
macroblock
[
y
][
x
]=
(
float
)
(((
rgammas
[
bayer_indices
[
1
]][
i
])-
blacks256
[
bayer_indices
[
1
]])/
gains
[
bayer_indices
[
1
]
]);
i
=(
int
)
macroblock
[
y
][
x
+
1
];
if
(
i
<
0
)
i
=
0
;
else
if
(
i
>
255
)
i
=
255
;
macroblock
[
y
][
x
+
1
]=
(
float
)
(((
rgammas
[
0
][
i
])-
blacks256
[
0
])/
gains
[
0
]);
macroblock
[
y
][
x
+
1
]=
(
float
)
(((
rgammas
[
bayer_indices
[
0
]][
i
])-
blacks256
[
bayer_indices
[
0
]])/
gains
[
bayer_indices
[
0
]
]);
i
=(
int
)
macroblock
[
y
+
1
][
x
];
if
(
i
<
0
)
i
=
0
;
else
if
(
i
>
255
)
i
=
255
;
macroblock
[
y
+
1
][
x
]=
(
float
)
(((
rgammas
[
3
][
i
])-
blacks256
[
3
])/
gains
[
3
]);
macroblock
[
y
+
1
][
x
]=
(
float
)
(((
rgammas
[
bayer_indices
[
3
]][
i
])-
blacks256
[
bayer_indices
[
3
]])/
gains
[
bayer_indices
[
3
]
]);
i
=(
int
)
macroblock
[
y
+
1
][
x
+
1
];
if
(
i
<
0
)
i
=
0
;
else
if
(
i
>
255
)
i
=
255
;
macroblock
[
y
+
1
][
x
+
1
]=
(
float
)
(((
rgammas
[
2
][
i
])-
blacks256
[
2
])/
gains
[
2
]);
macroblock
[
y
+
1
][
x
+
1
]=
(
float
)
(((
rgammas
[
bayer_indices
[
2
]][
i
])-
blacks256
[
bayer_indices
[
2
]])/
gains
[
bayer_indices
[
2
]
]);
}
}
else
{
for
(
y
=
0
;
y
<
16
;
y
+=
2
)
for
(
x
=
0
;
x
<
16
;
x
+=
2
)
{
i
=(
int
)
macroblock
[
y
][
x
];
if
(
i
<
0
)
i
=
0
;
else
if
(
i
>
255
)
i
=
255
;
macroblock
[
y
][
x
]=
(
float
)
((
rgammas
[
1
][
i
])-
blacks256
[
1
]);
macroblock
[
y
][
x
]=
(
float
)
((
rgammas
[
bayer_indices
[
1
]][
i
])-
blacks256
[
bayer_indices
[
1
]
]);
i
=(
int
)
macroblock
[
y
][
x
+
1
];
if
(
i
<
0
)
i
=
0
;
else
if
(
i
>
255
)
i
=
255
;
macroblock
[
y
][
x
+
1
]=
(
float
)
((
rgammas
[
0
][
i
])-
blacks256
[
0
]);
macroblock
[
y
][
x
+
1
]=
(
float
)
((
rgammas
[
bayer_indices
[
0
]][
i
])-
blacks256
[
bayer_indices
[
0
]
]);
i
=(
int
)
macroblock
[
y
+
1
][
x
];
if
(
i
<
0
)
i
=
0
;
else
if
(
i
>
255
)
i
=
255
;
macroblock
[
y
+
1
][
x
]=
(
float
)
((
rgammas
[
3
][
i
])-
blacks256
[
3
]);
macroblock
[
y
+
1
][
x
]=
(
float
)
((
rgammas
[
bayer_indices
[
3
]][
i
])-
blacks256
[
bayer_indices
[
3
]
]);
i
=(
int
)
macroblock
[
y
+
1
][
x
+
1
];
if
(
i
<
0
)
i
=
0
;
else
if
(
i
>
255
)
i
=
255
;
macroblock
[
y
+
1
][
x
+
1
]=
(
float
)
((
rgammas
[
2
][
i
])-
blacks256
[
2
]);
macroblock
[
y
+
1
][
x
+
1
]=
(
float
)
((
rgammas
[
bayer_indices
[
2
]][
i
])-
blacks256
[
bayer_indices
[
2
]
]);
}
}
}
...
...
@@ -835,16 +844,60 @@ public class JP46_Reader_camera0 extends PlugInFrame implements ActionListener {
}
}
}
if
(
FLIPH
!=
0
)
ip_src
.
flipHorizontal
();
/* To correct Bayer */
if
(
FLIPV
!=
0
)
ip_src
.
flipVertical
();
/* To correct Bayer */
if
(
FLIPH
!=
0
)
{
ip_src
.
flipHorizontal
();
/* To correct Bayer */
}
if
(
FLIPV
!=
0
)
{
ip_src
.
flipVertical
();
/* To correct Bayer */
}
/* Is it needed here ? */
/* imp.draw();
imp.show(); **/
if
(
use_imp_src
)
copyProperties
(
imp
,
imp_src
);
if
(
fix_bayer
)
{
shiftToBayer
(
use_imp_src
?
imp_src:
imp
);
}
return
use_imp_src
;
}
/**
* Shift image vertically and/or horizontally to make it with BAYER_MODE=0 (RG/GB)
* @param imp_src image, will be modified
* @return true if any changes were applied
*/
public
boolean
shiftToBayer
(
ImagePlus
imp
)
{
int
bayer_mode
=
Integer
.
parseInt
((
String
)
imp
.
getProperty
(
"BAYER_MODE"
));
int
flip_vert
=
Integer
.
parseInt
((
String
)
imp
.
getProperty
(
"FLIPV"
));
int
flip_hor
=
Integer
.
parseInt
((
String
)
imp
.
getProperty
(
"FLIPH"
));
bayer_mode
^=
flip_hor
+
(
flip_vert
<<
1
);
if
(
bayer_mode
==
0
)
return
false
;
int
width
=
imp
.
getWidth
();
int
height
=
imp
.
getHeight
();
float
[]
pixels
=
(
float
[])
imp
.
getProcessor
().
getPixels
();
if
((
bayer_mode
&
1
)
!=
0
)
{
// horizontal shift
System
.
arraycopy
(
pixels
,
1
,
pixels
,
0
,
pixels
.
length
-
1
);
// shift left by 1 pixel (last column will be wrong)
for
(
int
row
=
0
;
row
<
height
;
row
++)
{
pixels
[(
row
+
1
)
*
width
-
1
]
=
pixels
[(
row
+
1
)
*
width
-
3
];
// set the last column with the nearest of the same Bayer
}
}
if
((
bayer_mode
&
2
)
!=
0
)
{
// vertical shift
System
.
arraycopy
(
pixels
,
width
,
pixels
,
0
,
pixels
.
length
-
width
);
// shift up by 1 row (last row will be wrong)
System
.
arraycopy
(
pixels
,
width
*
(
height
-
3
),
pixels
,
width
*
(
height
-
1
),
width
);
// set the row column with the nearest of the same Bayer
}
bayer_mode
=
flip_hor
+
(
flip_vert
<<
1
);
imp
.
setProperty
(
"BAYER_MODE"
,
""
+
bayer_mode
);
return
true
;
}
/* reverses gamma calculations in the camera
returns double[] table , in the range 0.0..255.996
*/
...
...
src/main/java/com/elphel/imagej/calibration/LaserPointer.java
View file @
fafa9362
...
...
@@ -542,7 +542,9 @@ public class LaserPointer{
int
width
){
ShowDoubleFloatArrays
sdfra_instance
=
null
;
if
(
this
.
debugLevel
>
1
)
sdfra_instance
=
new
ShowDoubleFloatArrays
();
// just for debugging?
// if (this.debugLevel>0) sdfra_instance= new ShowDoubleFloatArrays(); // just for debugging?
if
(
this
.
debugLevel
>
4
)
sdfra_instance
=
new
ShowDoubleFloatArrays
();
// just for debugging?
boolean
show_debug
=
sdfra_instance
!=
null
;
DoubleGaussianBlur
gb
=
new
DoubleGaussianBlur
();
double
initialScale
=
0.5
;
int
height
=
pixels
.
length
/
width
;
...
...
@@ -580,18 +582,6 @@ public class LaserPointer{
}
index
+=
width
;
}
/*
if (i*dwidth+j>=dpixels.length){
System.out.println(
"dpixels.length="+dpixels.length+"\n"+
"width="+width+"\n"+
"height="+height+"\n"+
"dwidth="+dwidth+"\n"+
"dheight="+dheight+"\n"+
"i="+i+"\n"+
"j="+j+"\n");
}
*/
dpixels
[
i
*
dwidth
+
j
]=
d
*
k
;
}
if
(
extraWidth
>
0
){
// j==dWidth-1
...
...
@@ -631,10 +621,10 @@ public class LaserPointer{
}
}
}
else
dpixels
=
pixels
.
clone
();
if
(
this
.
debugLevel
>
2
)
sdfra_instance
.
showArrays
(
dpixels
,
dwidth
,
dheight
,
"decimated"
);
if
(
show_debug
&&
(
this
.
debugLevel
>
2
)
)
sdfra_instance
.
showArrays
(
dpixels
,
dwidth
,
dheight
,
"decimated"
);
double
[]
dpixels_lp
=
dpixels
.
clone
();
gb
.
blurDouble
(
dpixels_lp
,
dwidth
,
dheight
,
scale
*
this
.
localContrastSigma
,
scale
*
this
.
localContrastSigma
,
0.01
);
if
(
this
.
debugLevel
>
2
)
sdfra_instance
.
showArrays
(
dpixels_lp
,
dwidth
,
dheight
,
"dpixels_lp"
);
if
(
show_debug
&&
(
this
.
debugLevel
>
2
)
)
sdfra_instance
.
showArrays
(
dpixels_lp
,
dwidth
,
dheight
,
"dpixels_lp"
);
double
sum
=
0.0
;
for
(
int
i
=
0
;
i
<
dpixels
.
length
;
i
++){
dpixels
[
i
]-=
dpixels_lp
[
i
];
...
...
@@ -642,26 +632,26 @@ public class LaserPointer{
sum
+=
dpixels_lp
[
i
];
}
double
corr
=(
1.0
-
this
.
localToGlobalContrast
)*
Math
.
sqrt
(
sum
/(
dwidth
*
dheight
));
if
(
this
.
debugLevel
>
2
)
sdfra_instance
.
showArrays
(
dpixels_lp
,
dwidth
,
dheight
,
"dpixels_var"
);
if
(
show_debug
&&
(
this
.
debugLevel
>
2
)
)
sdfra_instance
.
showArrays
(
dpixels_lp
,
dwidth
,
dheight
,
"dpixels_var"
);
gb
.
blurDouble
(
dpixels_lp
,
dwidth
,
dheight
,
scale
*
this
.
localContrastSigma
,
scale
*
this
.
localContrastSigma
,
0.01
);
if
(
this
.
debugLevel
>
2
)
sdfra_instance
.
showArrays
(
dpixels_lp
,
dwidth
,
dheight
,
"dpixels_var_blur"
);
if
(
show_debug
&&
(
this
.
debugLevel
>
2
)
)
sdfra_instance
.
showArrays
(
dpixels_lp
,
dwidth
,
dheight
,
"dpixels_var_blur"
);
for
(
int
i
=
0
;
i
<
dpixels
.
length
;
i
++){
dpixels_lp
[
i
]=
this
.
localToGlobalContrast
*
Math
.
sqrt
(
dpixels_lp
[
i
])+
corr
;
dpixels
[
i
]/=
dpixels_lp
[
i
];
}
if
(
this
.
debugLevel
>
2
)
sdfra_instance
.
showArrays
(
dpixels_lp
,
dwidth
,
dheight
,
"dpixels_denom"
);
if
(
show_debug
&&
(
this
.
debugLevel
>
2
)
)
sdfra_instance
.
showArrays
(
dpixels_lp
,
dwidth
,
dheight
,
"dpixels_denom"
);
if
(
this
.
patternLowPassSigma
>
0
)
{
if
(
this
.
debugLevel
>
2
)
sdfra_instance
.
showArrays
(
dpixels
,
dwidth
,
dheight
,
"dpixels_normalized"
);
if
(
show_debug
&&
(
this
.
debugLevel
>
2
)
)
sdfra_instance
.
showArrays
(
dpixels
,
dwidth
,
dheight
,
"dpixels_normalized"
);
gb
.
blurDouble
(
dpixels
,
dwidth
,
dheight
,
scale
*
this
.
patternLowPassSigma
,
scale
*
this
.
patternLowPassSigma
,
0.01
);
}
if
(
this
.
debugLevel
>
1
)
sdfra_instance
.
showArrays
(
dpixels
,
dwidth
,
dheight
,
"dpixels_norm_blur"
);
if
(
show_debug
&&
(
this
.
debugLevel
>
1
)
)
sdfra_instance
.
showArrays
(
dpixels
,
dwidth
,
dheight
,
"dpixels_norm_blur"
);
int
[]
ipixels
=
new
int
[
dpixels
.
length
];
for
(
int
i
=
0
;
i
<
dpixels
.
length
;
i
++){
if
(
dpixels
[
i
]>
this
.
patternThreshold
)
ipixels
[
i
]=
1
;
else
if
(
dpixels
[
i
]<-
this
.
patternThreshold
)
ipixels
[
i
]=-
1
;
else
ipixels
[
i
]=
0
;
}
if
(
this
.
debugLevel
>
1
)
sdfra_instance
.
showArrays
(
ipixels
,
dwidth
,
dheight
,
"ipixels_threshold"
);
if
(
show_debug
&&
(
this
.
debugLevel
>
1
)
)
sdfra_instance
.
showArrays
(
ipixels
,
dwidth
,
dheight
,
"ipixels_threshold"
);
int
maxDist
=
(
int
)
Math
.
round
(
scale
*
this
.
maximalCellSize
);
if
(
maxDist
<
1
)
maxDist
=
1
;
...
...
@@ -672,28 +662,29 @@ public class LaserPointer{
dwidth
,
(
pass
&
1
)==
0
,
// false, // each black cell should have white in all 4 quadrants
maxDist
,
this
.
bordersOK
this
.
bordersOK
,
show_debug
);
if
(
this
.
debugLevel
>
2
)
sdfra_instance
.
showArrays
(
ipixels
,
dwidth
,
dheight
,
"pass-"
+
pass
);
if
(
show_debug
&&
(
this
.
debugLevel
>
2
)
)
sdfra_instance
.
showArrays
(
ipixels
,
dwidth
,
dheight
,
"pass-"
+
pass
);
}
//blur-threshold-grow
// convert to Double (white cells - 1.0, black and none - 0.0)
for
(
int
i
=
0
;
i
<
dpixels
.
length
;
i
++)
dpixels
[
i
]=
(
ipixels
[
i
]>
0
)?
1.0
:
0.0
;
// blur result with sigma > cell period to find continuous pattern cell areas
gb
.
blurDouble
(
dpixels
,
dwidth
,
dheight
,
scale
*
this
.
localContrastSigma
,
scale
*
this
.
localContrastSigma
,
0.01
);
if
(
this
.
debugLevel
>
2
)
sdfra_instance
.
showArrays
(
dpixels
,
dwidth
,
dheight
,
"white_blurred"
);
if
(
show_debug
&&
(
this
.
debugLevel
>
2
)
)
sdfra_instance
.
showArrays
(
dpixels
,
dwidth
,
dheight
,
"white_blurred"
);
// Threshold to boolean mask
boolean
[]
dmask
=
new
boolean
[
dpixels
.
length
];
for
(
int
i
=
0
;
i
<
dpixels
.
length
;
i
++)
dmask
[
i
]=
(
dpixels
[
i
]>=
this
.
blurredMaskThreshold
);
if
(
this
.
debugLevel
>
1
)
sdfra_instance
.
showArrays
(
dmask
,
dwidth
,
dheight
,
"white_threshold"
);
if
(
show_debug
&&
(
this
.
debugLevel
>
1
)
)
sdfra_instance
.
showArrays
(
dmask
,
dwidth
,
dheight
,
"white_threshold"
);
int
iBlurMaskGrow
=
(
int
)
Math
.
round
(
scale
*
this
.
localContrastSigma
);
// does in need separate coefficient?
growMask
(
dmask
,
//boolean [] pixels,
dwidth
,
// int width,
iBlurMaskGrow
);
//int grow);
if
(
this
.
debugLevel
>
1
)
sdfra_instance
.
showArrays
(
dmask
,
dwidth
,
dheight
,
"white_threshold_grown"
+
iBlurMaskGrow
);
if
(
show_debug
&&
(
this
.
debugLevel
>
1
)
)
sdfra_instance
.
showArrays
(
dmask
,
dwidth
,
dheight
,
"white_threshold_grown"
+
iBlurMaskGrow
);
// Mask out white cells outside of the compact areas just found
for
(
int
i
=
0
;
i
<
dpixels
.
length
;
i
++)
if
(!
dmask
[
i
])
ipixels
[
i
]=
0
;
if
(
this
.
debugLevel
>
1
)
sdfra_instance
.
showArrays
(
ipixels
,
dwidth
,
dheight
,
"ipixels_masked"
);
if
(
show_debug
&&
((
this
.
debugLevel
>
1
))
)
sdfra_instance
.
showArrays
(
ipixels
,
dwidth
,
dheight
,
"ipixels_masked"
);
boolean
[]
mask
=
new
boolean
[
pixels
.
length
];
if
(
this
.
decimatePatternFilter
>
1
){
for
(
int
i
=
0
;
i
<
pixels
.
length
;
i
++){
...
...
@@ -764,11 +755,12 @@ public class LaserPointer{
int
width
,
boolean
fromBlack
,
int
maxDist
,
boolean
bordersOK
boolean
bordersOK
,
boolean
show_debug
){
int
height
=
pixels
.
length
/
width
;
ShowDoubleFloatArrays
sdfra_instance
=
null
;
if
(
this
.
debugLevel
>
1
)
sdfra_instance
=
new
ShowDoubleFloatArrays
();
// just for debugging?
if
(
show_debug
)
sdfra_instance
=
new
ShowDoubleFloatArrays
();
// just for debugging?
int
[]
distLeft
=
new
int
[
pixels
.
length
];
int
[]
distRight
=
new
int
[
pixels
.
length
];
// also used for down
...
...
@@ -789,14 +781,14 @@ public class LaserPointer{
distRight
[
index2
--]=
v2
;
}
}
if
(
this
.
debugLevel
>
3
){
if
(
show_debug
&&
(
this
.
debugLevel
>
3
)
){
sdfra_instance
.
showArrays
(
distLeft
,
width
,
height
,
"distLeft-"
+
fromBlack
);
sdfra_instance
.
showArrays
(
distRight
,
width
,
height
,
"distRight-"
+
fromBlack
);
}
// combine two (max distance)
for
(
int
i
=
0
;
i
<
pixels
.
length
;
i
++)
if
(
distRight
[
i
]>
distLeft
[
i
])
distLeft
[
i
]=
distRight
[
i
];
if
(
this
.
debugLevel
>
3
)
sdfra_instance
.
showArrays
(
distLeft
,
width
,
height
,
"comboLeftRight-"
+
fromBlack
);
if
(
show_debug
&&
(
this
.
debugLevel
>
3
)
)
sdfra_instance
.
showArrays
(
distLeft
,
width
,
height
,
"comboLeftRight-"
+
fromBlack
);
// Down
...
...
@@ -807,7 +799,7 @@ public class LaserPointer{
v1
=
distRight
[
index1
++]+
1
;
distRight
[
i
]=
(
v1
>
distLeft
[
i
])?
distLeft
[
i
]:
v1
;
}
if
(
this
.
debugLevel
>
3
)
sdfra_instance
.
showArrays
(
distRight
,
width
,
height
,
"distDown-"
+
fromBlack
);
if
(
show_debug
&&
(
this
.
debugLevel
>
3
)
)
sdfra_instance
.
showArrays
(
distRight
,
width
,
height
,
"distDown-"
+
fromBlack
);
// Up
for
(
int
j
=
pixels
.
length
-
width
;
j
<
pixels
.
length
;
j
++)
distUp
[
j
]=
bordersOK
?
0
:
distLeft
[
j
];
index1
=
pixels
.
length
-
1
;
...
...
@@ -816,10 +808,10 @@ public class LaserPointer{
v1
=
distUp
[
index1
--]+
1
;
distUp
[
i
]=
(
v1
>
distLeft
[
i
])?
distLeft
[
i
]:
v1
;
}
if
(
this
.
debugLevel
>
3
)
sdfra_instance
.
showArrays
(
distUp
,
width
,
height
,
"distUp-"
+
fromBlack
);
if
(
show_debug
&&
(
this
.
debugLevel
>
3
)
)
sdfra_instance
.
showArrays
(
distUp
,
width
,
height
,
"distUp-"
+
fromBlack
);
// combine two (max distance)
for
(
int
i
=
0
;
i
<
pixels
.
length
;
i
++)
if
(
distUp
[
i
]>
distRight
[
i
])
distRight
[
i
]=
distUp
[
i
];
if
(
this
.
debugLevel
>
3
)
sdfra_instance
.
showArrays
(
distRight
,
width
,
height
,
"combo-"
+
fromBlack
);
if
(
show_debug
&&
(
this
.
debugLevel
>
3
)
)
sdfra_instance
.
showArrays
(
distRight
,
width
,
height
,
"combo-"
+
fromBlack
);
// Now distRight contains the longest of 4 quadrants distance from "good" pixels - remove bad opposite side ones
for
(
int
i
=
0
;
i
<
pixels
.
length
;
i
++)
if
((
distRight
[
i
]>
maxDist
)
&&
(
pixels
[
i
]!=
sign
))
pixels
[
i
]=
0
;
// if opposite signe (or 0) make 0
}
...
...
@@ -898,7 +890,7 @@ public class LaserPointer{
String
title
,
int
debugLevel
// debug level (normal == 1)
){
int
debugTiming
=
1
;
int
debugTiming
=
1
;
// used >3
if
(
debugLevel
>
debugTiming
)
printTimingInit
();
boolean
skipFirst
=
scaleExposureForLasers
>
0.0
;
// do not use no-pointer image (may have different exposure time)
/// if (scaleExposureForLasers>0) saturationRed*=scaleExposureForLasers; // scaled to reduced exposure time
...
...
src/main/java/com/elphel/imagej/calibration/MatchSimulatedPattern.java
View file @
fafa9362
This diff is collapsed.
Click to expand it.
src/main/java/com/elphel/imagej/calibration/hardware/CamerasInterface.java
View file @
fafa9362
...
...
@@ -899,6 +899,7 @@ public class CamerasInterface{
return
setupCameraAcquisition
(
Double
.
NaN
);
}
public
boolean
setupCameraAcquisition
(
final
double
exposureScale
){
final
boolean
mp14
=
true
;
// FIXME: Modified for 14Mpix
final
int
ipLength
=
this
.
resetURLs
.
length
;
final
boolean
[]
results
=
new
boolean
[
ipLength
];
for
(
int
chn
=
0
;
chn
<
ipLength
;
chn
++)
results
[
chn
]=(
this
.
sensorPresent
[
chn
]!=
null
);
...
...
@@ -917,14 +918,15 @@ public class CamerasInterface{
}
startAndJoin
(
threads
);
if
(
Double
.
isNaN
(
exposureScale
)){
// full init
int
nRepeat
=
this
.
setupTriggerMode
?
4
:
1
;
// int nRepeat=this.setupTriggerMode?4:1;
int
nRepeat
=
this
.
setupTriggerMode
?
4
:
2
;
// FIXME: Modified for 14Mpix
if
(
this
.
nc393
)
nRepeat
++;
// is it needed?
for
(
int
i
=
0
;
i
<
nRepeat
;
i
++){
if
(
this
.
debugLevel
>
0
)
System
.
out
.
println
((
i
+
1
)+
" of "
+
nRepeat
+
": Triggering cameras to give parameters a chance to propagate"
);
trigger
();
try
{
Thread
.
sleep
(
1000
);
// ms
Thread
.
sleep
(
2000
);
// ms // FIXME: Modified for 14Mpix
}
catch
(
InterruptedException
e
)
{
...
...
@@ -932,6 +934,16 @@ public class CamerasInterface{
}
}
}
else
if
(
mp14
)
{
try
{
Thread
.
sleep
(
2000
);
// ms // FIXME: Modified for 14Mpix
}
catch
(
InterruptedException
e
)
{
System
.
out
.
println
(
"awakened prematurely"
);
}
trigger
();
}
boolean
result
=
true
;
for
(
int
chn
=
0
;
chn
<
ipLength
;
chn
++)
if
(
this
.
sensorPresent
[
chn
]!=
null
)
result
&=
results
[
chn
];
...
...
@@ -1290,7 +1302,8 @@ public class CamerasInterface{
DocumentBuilderFactory
dbf
=
DocumentBuilderFactory
.
newInstance
();
DocumentBuilder
db
=
dbf
.
newDocumentBuilder
();
String
url
=
metaURLs
[
ipIndex
];
if
(
debugLevel
>
2
)
System
.
out
.
println
(
"timestampIPs:"
+
url
);
// if (debugLevel>2) System.out.println("timestampIPs:" + url );
if
(
debugLevel
>
0
)
System
.
out
.
println
(
"timestampIPs:"
+
url
);
dom
=
db
.
parse
(
url
);
if
(!
dom
.
getDocumentElement
().
getNodeName
().
equals
(
"meta"
))
{
System
.
out
.
println
(
"Root element: expected 'meta', got'"
+
dom
.
getDocumentElement
().
getNodeName
()+
"'"
);
...
...
@@ -1383,7 +1396,13 @@ public class CamerasInterface{
startAndJoin
(
threads
);
}
// public boolean preTrigger() { // mt9f002 fails if more than 1-3 sec between triggers
// return true;
// }
public
ImagePlus
[]
getImages
(
final
boolean
[]
acquire
,
boolean
resetAndTrigger
,
final
boolean
show
){
final
boolean
dual_trig
=
false
;
final
boolean
[]
acquireIPs
=
selectIPs
(
acquire
);
if
(
this
.
debugLevel
>
2
)
{
System
.
out
.
println
(
"getImages(...) 2"
);
...
...
@@ -1391,8 +1410,20 @@ public class CamerasInterface{
}
if
(
resetAndTrigger
)
{
try
{
// FIXME: Make conditional for 14MPix
Thread
.
sleep
(
2000
);
}
catch
(
InterruptedException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
resetCameras
();
trigger
();
if
(
dual_trig
)
{
timestampIPs
(
acquireIPs
);
// ignoring results, just wait
resetCameras
();
// trigger();
jp4_Instances
[
0
].
readDummyURL
(
"http://192.168.0.236/parsedit.php?immediate&TRIG_PERIOD=1*0"
);
}
}
final
double
[]
timestamps
=
timestampIPs
(
acquireIPs
);
if
(
this
.
debugLevel
>
2
)
System
.
out
.
println
(
"getImages(): this.imagesIP.length="
+
this
.
imagesIP
.
length
);
...
...
@@ -1590,6 +1621,12 @@ public class CamerasInterface{
if
(
debugLevel
>
2
)
System
.
out
.
println
(
String
.
format
(
"this.laserPointers.setLasers (0x%x)"
,
sequence
[
nSeqNum
]));
}
resetIPs
(
selectIPs
(
lasersIPs
));
// flush buffer
try
{
// FIXME: Make conditional for 14MPix
Thread
.
sleep
(
2000
);
}
catch
(
InterruptedException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
trigger
();
// trigger cameras
ipIndexAtomic
.
set
(
0
);
final
int
fnSeqNum
=
nSeqNum
;
...
...
@@ -1613,6 +1650,8 @@ public class CamerasInterface{
System
.
out
.
println
(
"==== "
+
imageURLs
[
ipIndex
]+
" opened in "
+
IJ
.
d2s
(
0.000000001
*(
System
.
nanoTime
()-
st
),
3
)+
" sec"
);
}
laserImagesIP
[
fnSeqNum
-
1
][
ipIndex
].
setProperty
(
"MIRRORED"
,
"NO"
);
// laserImagesIP[fnSeqNum-1][ipIndex].setTitle("raw"+fnSeqNum); //FIXME:Debugging
// laserImagesIP[fnSeqNum-1][ipIndex].show(); //FIXME:Debugging
}
}
};
...
...
src/main/java/com/elphel/imagej/jp4/JP46_Reader_camera.java
View file @
fafa9362
...
...
@@ -85,6 +85,11 @@ public class JP46_Reader_camera implements PlugIn, ActionListener {
*
*/
private
static
final
long
serialVersionUID
=
390855361964415147L
;
public
static
int
[][]
BAYER_INDICES
=
{
{
0
,
1
,
2
,
3
},
{
1
,
0
,
3
,
2
},
{
2
,
3
,
0
,
1
},
{
3
,
2
,
1
,
0
}};
Panel
panel1
;
Panel
confpanel
;
Frame
instance
;
...
...
@@ -93,7 +98,7 @@ public class JP46_Reader_camera implements PlugIn, ActionListener {
String
arg
;
static
File
dir
;
public
boolean
fix_bayer
=
true
;
// shift image (replacing last row/column) if (corrected for flips) BAYER_MODE != 0
public
String
camera_url
=
"http://192.168.0.236:8081/"
;
public
String
camera_img
=
"bimg"
;
public
String
camera_img_new
=
"towp/wait/bimg"
;
// will always wait for the next image (repetitive acquisitions get new images)
...
...
@@ -109,14 +114,26 @@ public class JP46_Reader_camera implements PlugIn, ActionListener {
public
void
run
(
String
arg
)
{
}
public
JP46_Reader_camera
(
Boolean
showGui
)
{
public
JP46_Reader_camera
(
Boolean
showGui
)
{
// default fix_bayer = true
if
(
showGui
)
initGui
();
}
public
JP46_Reader_camera
()
{
public
JP46_Reader_camera
()
{
// default fix_bayer = true
initGui
();
}
public
JP46_Reader_camera
(
Boolean
showGui
,
int
fix_bayer
)
{
if
(
showGui
)
initGui
();
this
.
fix_bayer
=
(
fix_bayer
!=
0
);
}
public
JP46_Reader_camera
(
int
fix_bayer
)
{
initGui
();
this
.
fix_bayer
=
(
fix_bayer
!=
0
);
}
// fix_bayer
private
void
initGui
()
{
if
(
headless
)
return
;
...
...
@@ -390,6 +407,8 @@ public class JP46_Reader_camera implements PlugIn, ActionListener {
if
(
imp
==
null
)
{
IJ
.
showMessage
(
"JP46 Reader Error"
,
"Could not open the URL: "
+
url
+
" as JPEG/JP46"
);
}
else
{
// imp.updateAndDraw();
// imp.show(); // updateAndDraw();
if
((
imp_src
==
null
)
&&
showImage
)
{
// System.out.println("show() 1");
imp
.
show
();
/* Shows before re-ordering*/
...
...
@@ -450,6 +469,7 @@ public class JP46_Reader_camera implements PlugIn, ActionListener {
}
boolean
jp46Reorder
(
ImagePlus
imp
,
long
[]
MakerNote
,
boolean
scale
,
ImagePlus
imp_src
)
{
// int MARGIN=2; // 2 pixels in JP4/JP46 mode around WOI
double
[]
gains
=
new
double
[
4
];
double
[]
blacks
=
new
double
[
4
];
double
[]
blacks256
=
new
double
[
4
];
...
...
@@ -459,6 +479,7 @@ public class JP46_Reader_camera implements PlugIn, ActionListener {
double
[][]
rgammas
=
new
double
[
4
][];
double
min_gain
;
long
WOI_LEFT
,
WOI_WIDTH
,
WOI_TOP
,
WOI_HEIGHT
,
BAYER_MODE
,
DCM_HOR
,
DCM_VERT
,
BIN_HOR
,
BIN_VERT
;
BAYER_MODE
=
0
;
long
COLOR_MODE
=
0
;
long
FLIPH
=
0
;
long
FLIPV
=
0
;
...
...
@@ -730,35 +751,36 @@ public class JP46_Reader_camera implements PlugIn, ActionListener {
}
}
/* apply gammas here */
int
[]
bayer_indices
=
BAYER_INDICES
[(
int
)
BAYER_MODE
];
if
(
MakerNote
!=
null
)
{
if
(
scale
)
{
for
(
y
=
0
;
y
<
16
;
y
+=
2
)
for
(
x
=
0
;
x
<
16
;
x
+=
2
)
{
i
=(
int
)
macroblock
[
y
][
x
];
if
(
i
<
0
)
i
=
0
;
else
if
(
i
>
255
)
i
=
255
;
macroblock
[
y
][
x
]=
(
float
)
(((
rgammas
[
1
][
i
])-
blacks256
[
1
])/
gains
[
1
]);
macroblock
[
y
][
x
]=
(
float
)
(((
rgammas
[
bayer_indices
[
1
]][
i
])-
blacks256
[
bayer_indices
[
1
]])/
gains
[
bayer_indices
[
1
]
]);
i
=(
int
)
macroblock
[
y
][
x
+
1
];
if
(
i
<
0
)
i
=
0
;
else
if
(
i
>
255
)
i
=
255
;
macroblock
[
y
][
x
+
1
]=
(
float
)
(((
rgammas
[
0
][
i
])-
blacks256
[
0
])/
gains
[
0
]);
macroblock
[
y
][
x
+
1
]=
(
float
)
(((
rgammas
[
bayer_indices
[
0
]][
i
])-
blacks256
[
bayer_indices
[
0
]])/
gains
[
bayer_indices
[
0
]
]);
i
=(
int
)
macroblock
[
y
+
1
][
x
];
if
(
i
<
0
)
i
=
0
;
else
if
(
i
>
255
)
i
=
255
;
macroblock
[
y
+
1
][
x
]=
(
float
)
(((
rgammas
[
3
][
i
])-
blacks256
[
3
])/
gains
[
3
]);
macroblock
[
y
+
1
][
x
]=
(
float
)
(((
rgammas
[
bayer_indices
[
3
]][
i
])-
blacks256
[
bayer_indices
[
3
]])/
gains
[
bayer_indices
[
3
]
]);
i
=(
int
)
macroblock
[
y
+
1
][
x
+
1
];
if
(
i
<
0
)
i
=
0
;
else
if
(
i
>
255
)
i
=
255
;
macroblock
[
y
+
1
][
x
+
1
]=
(
float
)
(((
rgammas
[
2
][
i
])-
blacks256
[
2
])/
gains
[
2
]);
macroblock
[
y
+
1
][
x
+
1
]=
(
float
)
(((
rgammas
[
bayer_indices
[
2
]][
i
])-
blacks256
[
bayer_indices
[
2
]])/
gains
[
bayer_indices
[
2
]
]);
}
}
else
{
for
(
y
=
0
;
y
<
16
;
y
+=
2
)
for
(
x
=
0
;
x
<
16
;
x
+=
2
)
{
i
=(
int
)
macroblock
[
y
][
x
];
if
(
i
<
0
)
i
=
0
;
else
if
(
i
>
255
)
i
=
255
;
macroblock
[
y
][
x
]=
(
float
)
((
rgammas
[
1
][
i
])-
blacks256
[
1
]);
macroblock
[
y
][
x
]=
(
float
)
((
rgammas
[
bayer_indices
[
1
]][
i
])-
blacks256
[
bayer_indices
[
1
]
]);
i
=(
int
)
macroblock
[
y
][
x
+
1
];
if
(
i
<
0
)
i
=
0
;
else
if
(
i
>
255
)
i
=
255
;
macroblock
[
y
][
x
+
1
]=
(
float
)
((
rgammas
[
0
][
i
])-
blacks256
[
0
]);
macroblock
[
y
][
x
+
1
]=
(
float
)
((
rgammas
[
bayer_indices
[
0
]][
i
])-
blacks256
[
bayer_indices
[
0
]
]);
i
=(
int
)
macroblock
[
y
+
1
][
x
];
if
(
i
<
0
)
i
=
0
;
else
if
(
i
>
255
)
i
=
255
;
macroblock
[
y
+
1
][
x
]=
(
float
)
((
rgammas
[
3
][
i
])-
blacks256
[
3
]);
macroblock
[
y
+
1
][
x
]=
(
float
)
((
rgammas
[
bayer_indices
[
3
]][
i
])-
blacks256
[
bayer_indices
[
3
]
]);
i
=(
int
)
macroblock
[
y
+
1
][
x
+
1
];
if
(
i
<
0
)
i
=
0
;
else
if
(
i
>
255
)
i
=
255
;
macroblock
[
y
+
1
][
x
+
1
]=
(
float
)
((
rgammas
[
2
][
i
])-
blacks256
[
2
]);
macroblock
[
y
+
1
][
x
+
1
]=
(
float
)
((
rgammas
[
bayer_indices
[
2
]][
i
])-
blacks256
[
bayer_indices
[
2
]
]);
}
}
}
...
...
@@ -771,16 +793,60 @@ public class JP46_Reader_camera implements PlugIn, ActionListener {
}
}
}
if
(
FLIPH
!=
0
)
ip_src
.
flipHorizontal
();
/* To correct Bayer */
if
(
FLIPV
!=
0
)
ip_src
.
flipVertical
();
/* To correct Bayer */
if
(
FLIPH
!=
0
)
{
ip_src
.
flipHorizontal
();
/* To correct Bayer */
}
if
(
FLIPV
!=
0
)
{
ip_src
.
flipVertical
();
/* To correct Bayer */
}
/* Is it needed here ? */
/* imp.draw();
imp.show(); **/
if
(
use_imp_src
)
copyProperties
(
imp
,
imp_src
);
if
(
fix_bayer
)
{
shiftToBayer
(
use_imp_src
?
imp_src:
imp
);
}
return
use_imp_src
;
}
/**
* Shift image vertically and/or horizontally to make it with BAYER_MODE=0 (RG/GB)
* @param imp_src image, will be modified
* @return true if any changes were applied
*/
public
boolean
shiftToBayer
(
ImagePlus
imp
)
{
int
bayer_mode
=
Integer
.
parseInt
((
String
)
imp
.
getProperty
(
"BAYER_MODE"
));
int
flip_vert
=
Integer
.
parseInt
((
String
)
imp
.
getProperty
(
"FLIPV"
));
int
flip_hor
=
Integer
.
parseInt
((
String
)
imp
.
getProperty
(
"FLIPH"
));
bayer_mode
^=
flip_hor
+
(
flip_vert
<<
1
);
if
(
bayer_mode
==
0
)
return
false
;
int
width
=
imp
.
getWidth
();
int
height
=
imp
.
getHeight
();
float
[]
pixels
=
(
float
[])
imp
.
getProcessor
().
getPixels
();
if
((
bayer_mode
&
1
)
!=
0
)
{
// horizontal shift
System
.
arraycopy
(
pixels
,
1
,
pixels
,
0
,
pixels
.
length
-
1
);
// shift left by 1 pixel (last column will be wrong)
for
(
int
row
=
0
;
row
<
height
;
row
++)
{
pixels
[(
row
+
1
)
*
width
-
1
]
=
pixels
[(
row
+
1
)
*
width
-
3
];
// set the last column with the nearest of the same Bayer
}
}
if
((
bayer_mode
&
2
)
!=
0
)
{
// vertical shift
System
.
arraycopy
(
pixels
,
width
,
pixels
,
0
,
pixels
.
length
-
width
);
// shift up by 1 row (last row will be wrong)
System
.
arraycopy
(
pixels
,
width
*
(
height
-
3
),
pixels
,
width
*
(
height
-
1
),
width
);
// set the row column with the nearest of the same Bayer
}
bayer_mode
=
flip_hor
+
(
flip_vert
<<
1
);
imp
.
setProperty
(
"BAYER_MODE"
,
""
+
bayer_mode
);
return
true
;
}
/* reverses gamma calculations in the camera
returns double[] table , in the range 0.0..255.996
*/
...
...
@@ -924,6 +990,22 @@ public class JP46_Reader_camera implements PlugIn, ActionListener {
}
return
data
;
}
public
boolean
readDummyURL
(
String
url
)
{
// throws IOException {
URL
camURL
=
null
;
URLConnection
urlConn
=
null
;
try
{
camURL
=
new
URL
(
url
);
urlConn
=
camURL
.
openConnection
();
urlConn
.
getHeaderFields
();
}
catch
(
MalformedURLException
e
){
System
.
out
.
println
(
"Please check the URL:"
+
e
.
toString
()
);
return
false
;
}
catch
(
IOException
e1
){
System
.
out
.
println
(
"Can't read from the Internet: "
+
e1
.
toString
()
);
return
false
;
}
return
true
;
}
long
[]
readElphelMakerNoteURL
(
String
url
,
int
len
,
double
[]
xtraExif
)
throws
IOException
{
URL
camURL
=
null
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment