forked from ItBitCo/JavaFlyCam
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlyCamera.java
More file actions
Latest commit
89 lines (79 loc) · 4.13 KB
/
Copy pathFlyCamera.java
File metadata and controls
89 lines (79 loc) · 4.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// The actual class FlyCamera reads images from camera.. -- 2017 February 27
// You need both FlyCapture2_C.dll and FlyCapture2.dll in your Java project folder
packagefly2cam; // (same API as fly0cam)
publicclassFlyCamera {
publicstaticfinalintFrameRate_15 = 3, FrameRate_30 = 4;
privateintrose, // actual number of rows = FlyCap2.fc2Image.rows/2
colz, // actual number of columns = FlyCap2.fc2Image.cols/2
tile, // see FlyCapture2Defs.fc2BayerTileFormat
errn; // returns an error number, see ErrorNumberText()
privatelongstuff; // used for error reporting, or not at all
<<<<<<< HEAD
publicnativebooleanConnect(intframeRate, intexposure); // required at start, sets rose,colz,tile
=======
publicnativebooleanConnect(intframeRate); // required at start, sets rose,colz,tile
>>>>>>> d3d7db5d385d62eb364cd15d20340987c4d9a5f2
publicnativebooleanNextFrame(byte[] pixels); // fills pixels, false if can't
publicnativevoidFinish(); // required at end to prevent memory leaks
static { System.loadLibrary("FlyCamera"); }
publicstaticStringErrorNumberText(interrno) { // to explain errn in toString()
if (errno == -20) return"ByteArray is not same size as received data";
switch (errno) {
case -1: return"No camera connected";
case0: return"No error";
case1: return"fc2CreateContext failed";
case2: return"fc2GetNumOfCameras failed";
case3: return"No cameras detected";
case4: return"fc2GetCameraFromIndex did not find first camera";
case5: return"fc2Connect failed to connect to first camera";
case6: return"fc2StartCapture failed";
case7: return"fc2CreateImage failed";
case8: return"No error";
case9: return"fc2RetrieveBuffer failed";
case10: return"rawImage.format = 0 (probably unset)";
case11: return"ByteArray to NextFrame is null";
case12: return"Connect failed or not called (context == null)";
case13: return"Something in context corrupted";
case14: return"ByteArray is way too short or too long";
case15: return"GetByteArrayElements failed (couldn't access bytes)";
case16: return"fc2RetrieveBuffer failed, possibly timeout";
case17: return"fc2GetImageData failed";
case18: return"No pixel data received";
case19: return"Unknown camera image size";
case20: return"No error";
case21: return"fc2StopCapture failed";
case22: return"fc2DestroyImage failed";
case23: return"Both fc2StopCapture and fc2DestroyImage failed";
case24: return"fc2CreateImage failed (RGB)";
case25: return"fc2ConvertImageTo (RGB) failed";
case26: return"fc2GetProperty failed";
case27: return"Unknown frame rate";
case28: return"fc2SetProperty failed";} //~switch
return"fc2RetrieveBuffer probably returned some format other than Bayer8";
} //~ErrorNumberText
publicintDimz() {return (rose<<16)+colz;} // access to image size from camera
publicintPixTile() {returntile;} // image Bayer encoding, frex RG/GB = 1, GB/RG = 3
publicStringtoString() {return"fly2cam.FlyCamera " + ErrorNumberText(errn);}
publicbooleanLive() {returntile>0;} // we have a live camera (fly2cam)
publicstaticvoidmain(String[] args) { // to test the interface
inttall = 0, wide = 0, pix = -1;
byte[] buff;
FlyCamerahello = newFlyCamera();
if (hello.Connect(0)) tall = hello.Dimz();
wide = tall&0xFFFF;
tall = tall>>16;
if (tall>0) if (wide>0) { // we got reasonable image size, get one image..
buff = newbyte[tall*wide*4];
if (hello.NextFrame(buff)) // got an image, extract 1st pixel..
pix = (((int)buff[0])<<24)|((((int)buff[1])&255)<<16)
| ((((int)buff[wide+wide])&255)<<8) | (((int)buff[wide+wide+1])&255);
elsepix = 0; // no image came
// set breakpoint here to look in the debugger, or else log pix
wide = pix;} // otherwise Java complains that it's unused
hello.Finish();
pix = 0;} //~main
publicFlyCamera() {
rose = 0;
colz = 0;
tile = 0;
errn = 0;}} //~FlyCamera (fly2cam) (F2)