Skip to content

Commit 34d3bf9

Browse files
committed
trying to debug the issue
1 parent 9d7e065 commit 34d3bf9

3 files changed

Lines changed: 75 additions & 20 deletions

File tree

python-bindings/ARToolKitNFT_py.cpp

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,32 @@ void matrixLerp(ARdouble src[3][4], ARdouble dst[3][4],
3333
}
3434

3535
int ARToolKitNFT::passVideoData(py::array_t<uint8_t> videoFrame, py::array_t<uint8_t> videoLuma) {
36-
auto videoFramePtr = static_cast<uint8_t *>(videoFrame.request().ptr);
37-
auto videoLumaPtr = static_cast<uint8_t *>(videoLuma.request().ptr);
36+
auto frame_info = videoFrame.request();
37+
auto luma_info = videoLuma.request();
3838

39-
std::copy(videoFramePtr, videoFramePtr + videoFrame.size(), this->videoFrame.get());
40-
std::copy(videoLumaPtr, videoLumaPtr + videoLuma.size(), this->videoLuma.get());
39+
ARLOGi("Video Frame Debug:\n");
40+
ARLOGi(" Dimensions: %ld\n", frame_info.ndim);
41+
ARLOGi(" Shape: Total elements: %ld\n", frame_info.shape[0]);
42+
ARLOGi(" Total size: %ld bytes\n", frame_info.size);
43+
ARLOGi(" Item size: %ld bytes\n", frame_info.itemsize);
4144

42-
return 0;
45+
ARLOGi("Video Luma Debug:\n");
46+
ARLOGi(" Dimensions: %ld\n", luma_info.ndim);
47+
ARLOGi(" Shape: Total elements: %ld\n", luma_info.shape[0]);
48+
ARLOGi(" Total size: %ld bytes\n", luma_info.size);
49+
ARLOGi(" Item size: %ld bytes\n", luma_info.itemsize);
50+
51+
uint8_t* frame_ptr = static_cast<uint8_t*>(frame_info.ptr);
52+
uint8_t* luma_ptr = static_cast<uint8_t*>(luma_info.ptr);
53+
54+
// Copy flattened data
55+
std::copy(frame_ptr, frame_ptr + frame_info.size, this->videoFrame.get());
56+
std::copy(luma_ptr, luma_ptr + luma_info.size, this->videoLuma.get());
57+
58+
ARLOGi("First few frame bytes: %u %u %u %u %u\n", frame_ptr[0], frame_ptr[1], frame_ptr[2], frame_ptr[3], frame_ptr[4]);
59+
ARLOGi("First few luma bytes: %u %u %u %u %u\n", luma_ptr[0], luma_ptr[1], luma_ptr[2], luma_ptr[3], luma_ptr[4]);
60+
61+
return 0;
4362
}
4463

4564
py::dict ARToolKitNFT::getNFTMarkerInfo(int markerIndex) {
@@ -124,17 +143,30 @@ int ARToolKitNFT::detectNFTMarker() {
124143
int kpmResultNum = -1;
125144

126145
if (this->detectedPage == -2) {
146+
ARLOGi("detectedPage = %d\n", this->detectedPage);
127147
kpmMatching(this->kpmHandle.get(), this->videoLuma.get());
128148
kpmGetResult(this->kpmHandle.get(), &kpmResult, &kpmResultNum);
129-
149+
if (kpmResultNum > 0) {
150+
ARLOGi("kpmMatching found %d results.\n", kpmResultNum);
151+
for (int i = 0; i < kpmResultNum; i++) {
152+
ARLOGi("kpmResult[%d]: pageNo = %d, error = %f, inlierNum = %d, camPoseF = %d\n",
153+
i,
154+
kpmResult[i].pageNo,
155+
kpmResult[i].error,
156+
kpmResult[i].inlierNum,
157+
kpmResult[i].camPoseF);
158+
}
159+
} else {
160+
ARLOGi("No kpmResults found.");
161+
}
130162
#if WITH_FILTERING
131163
this->ftmi = arFilterTransMatInit(this->filterSampleRate,
132164
this->filterCutoffFrequency);
133165
#endif
134166

135167
for (int i = 0; i < kpmResultNum; i++) {
136168
if (kpmResult[i].camPoseF == 0) {
137-
169+
ARLOGi("kpmResult[i].pageNo = %d\n", kpmResult[i].pageNo);
138170
float trans[3][4];
139171
this->detectedPage = kpmResult[i].pageNo;
140172
std::copy(&kpmResult[i].camPose[0][0], &kpmResult[i].camPose[0][0] + 3 * 4, &trans[0][0]);
@@ -178,8 +210,8 @@ int ARToolKitNFT::setupAR2() {
178210
this->ar2Handle = tempHandle;
179211

180212
// Settings for devices with single-core CPUs.
181-
ar2SetTrackingThresh(this->ar2Handle, 5.0);
182-
ar2SetSimThresh(this->ar2Handle, 0.50);
213+
ar2SetTrackingThresh(this->ar2Handle, 2.0); // Lowering tolerance.
214+
ar2SetSimThresh(this->ar2Handle, 0.3); // Increase similarity tolerance.
183215
ar2SetSearchFeatureNum(this->ar2Handle, 16);
184216
ar2SetSearchSize(this->ar2Handle, 6);
185217
ar2SetTemplateSize1(this->ar2Handle, 6);

python-bindings/example.py

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,50 @@
44
from PIL import Image
55

66
async def main():
7-
arnft = arcontrollerNFT.ARControllerNFT(1920, 1021, '../examples/Data/camera_para.dat')
7+
arnft = arcontrollerNFT.ARControllerNFT(1637, 2048, '../examples/Data/camera_para.dat')
88
nft = await arnft._initialize()
99
await nft.loadNFTMarkers(['../examples/DataNFT/pinball'])
1010
print(nft)
1111

12-
nft.trackNFTMarkerId(nft.id)
12+
obj = nft.trackNFTMarkerId(nft.id)
13+
print('obj is: ', obj)
1314

1415
# Load the test image
1516
image_path = './pinball-test.png'
17+
1618
image = Image.open(image_path)
19+
print(f'Original image shape: {image.size}, mode: {image.mode}')
1720
image = image.convert('RGBA')
18-
21+
image_gray = image.convert('L')
22+
gray_data = np.array(image_gray)
23+
nft.setGrayData(gray_data)
24+
# image = image.transpose(Image.Transpose.ROTATE_90)
25+
# image = image.transpose(Image.Transpose.ROTATE_270)
26+
# image = image.transpose(Image.Transpose.FLIP_TOP_BOTTOM)
27+
# image = image.transpose(Image.Transpose.ROTATE_90)
28+
# image = image.resize((640, 480), Image.Resampling.LANCZOS)
29+
# image = image.transpose(Image.Transpose.FLIP_LEFT_RIGHT)
30+
# image.show()
31+
print(f'Input image shape: {image.size}, mode: {image.mode}')
32+
print(f"First pixel values: {image.getpixel((0, 0))}")
33+
rgba = np.ascontiguousarray(np.array(image), np.uint8)
34+
# rgba = np.transpose(rgba, (1, 0, 2)) # Swap height and width dimensions
35+
# rgba = np.transpose(rgba)
1936
# Flip the image vertically
20-
#image = image.transpose(Image.FLIP_TOP_BOTTOM)
21-
22-
image_data = np.array(image)
23-
print('image_data:', image_data)
37+
# image = image.transpose(Image.FLIP_TOP_BOTTOM)
2438

2539
# Create a mock image object with the data attribute
2640
class MockImage:
27-
def __init__(self, data):
28-
self.data = data
41+
def __init__(self, array):
42+
self.data = array
43+
self.width = array.shape[1] # Width of the image
44+
self.height = array.shape[0] # Height of the image
45+
self.format = 'RGBA' # Or the format expected by the binding (e.g., 'BGRA')
46+
47+
mock_image = MockImage(rgba)
2948

30-
mock_image = MockImage(image_data)
49+
print('mock_image type: ', type(mock_image.data))
50+
print('mock_image width:', mock_image.data.shape)
3151

3252
# Add event listener for detecting NFT marker
3353
def on_get_nft_marker(ev):
@@ -42,7 +62,9 @@ def on_get_nft_marker(ev):
4262

4363
# Process the image
4464
print("Processing image...")
45-
nft.process(mock_image)
65+
for i in range(1):
66+
nft.process(mock_image)
67+
await asyncio.sleep(0) # let event loop dispatch
4668
print("Image processed.")
4769

4870
asyncio.run(main())

python-bindings/src/artoolkitnft/arcontrollerNFT.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def process(self, image):
7272
for i in range(nftMarkerCount):
7373
nftMarkerInfo = self.getNFTMarker(i)
7474
markerType = artoolkitnft_core.NFT_MARKER
75+
print('nftMarkerInfo:', nftMarkerInfo)
7576

7677
if nftMarkerInfo['found']:
7778
self.nftMarkerFound = i

0 commit comments

Comments
 (0)