-
Notifications
You must be signed in to change notification settings - Fork 189
TcpRequest
Example of requesting detection from a Find-Object's server.
Find-Object 0.5.0+ required
In this example, a Find-Object instance is running and wait on TCP for images coming from clients. When receiving an image, it will try to detect already loaded objects in the image. This approach can be useful is you don't want to reload the vocabulary each time a new image from an outside client is received.
- Files: box.png, box_in_scene.png
- Start Find-Object in console mode with image server activated:
$ Find-Object.exe --console --object box.png --config "" --General/invertedSearch false --Camera/6useTcpCamera "true" --Camera/8port 5000 --General/port 6000 --General/autoStartCamera "true"
[ INFO] Options:
[ INFO] GUI mode = false
[ INFO] Object path: "box.png"
[ INFO] Scene path: ""
[ INFO] JSON path: ""
[ INFO] Settings path: ""
[ INFO] Param "General/invertedSearch"="false"
[ INFO] Param "Camera/6useTcpCamera"="true"
[ INFO] Param "Camera/8port"="5000"
[ INFO] Param "General/port"="6000"
[ INFO] Settings set to defaults.
[ INFO] Load file box.png
[ INFO] Features extraction from 1 objects...
[ INFO] Extracting descriptors from object 1...
[ INFO] 550 descriptors extracted from object 1 (in 60 ms)
[ INFO] Features extraction from 1 objects... done! (62 ms)
[ INFO] Updating global descriptors matrix: Objects=1, total descriptors=550, dim=128, type=5
[ INFO] Creating vocabulary...
[ INFO] Object 1, 550 words from 550 descriptors (550 words, 0 ms)
[ INFO] Creating vocabulary... done! size=550 (12 ms)
[ INFO] Detection sent on port: 6000 (IP=127.0.0.1)
[ INFO] CameraTCP: listening to port 5000 (IP=127.0.0.1)
We use only one object here, but you could use --objects directory/objects
to load multiple objects from a directory. With null config file, default parameters are used. We specify camera TCP parameters on the command line. Find-Object is running and waiting for images on port 5000. It will also send detection results on port 6000.
- We want another application to ask Find-Object for detection on a specified image. The code example TcpRequest shows how to send an image through TCP to Find-Object and receive a response. Let's try this:
$ find_object-tcpRequest.exe --json "out.json" --scene box_in_scene.png --out 5000 --in 6000
Image published (365703 bytes), waiting for response...
Response received! (735 ms)
Object 1 detected.
JSON written to "out.json"
The "--json path" option makes it able to save the response into JSON file format as shown here:
{
"object_1" : {
"filename" : "box.png",
"height" : 223,
"homography" : [
0.5838476090426061,
0.03695318946765691,
-0.0001409410069874582,
-0.2048524415931983,
0.5008256527052151,
-0.0003875521492992923,
146.5362507255067,
199.5632576138089,
1.0
],
"inliers" : 68,
"outliers" : 157,
"width" : 324
},
"objects" : [ "object_1" ]
}
In 0.6.1, we can setup just only one port to send/receive requests. We can also set multiple TCP servers (created on different ports) to do multiple detections at the same time.
$ Find-Object.exe --console --object box.png --General/invertedSearch false --General/port 6000 --tcp_threads 4
[ INFO] Options:
[ INFO] GUI mode = false
[ INFO] Object path: "box.png"
[ INFO] Scene path: ""
[ INFO] JSON path: ""
[ INFO] Settings path: "/home/mathieu/.find_object/config.ini"
[ INFO] Vocabulary path: ""
[ INFO] Param "General/invertedSearch"="false"
[ INFO] Param "General/port"="6000"
[ INFO] Settings loaded from /home/mathieu/.find_object/config.ini.
[ INFO] Added object 1 (box.png)
[ INFO] Features extraction from 1 objects...
[ INFO] Extracting descriptors from object 1...
[ INFO] 550 descriptors extracted from object 1 (in 85 ms)
[ INFO] Features extraction from 1 objects... done! (85 ms)
[ INFO] Updating global descriptors matrix: Objects=1, total descriptors=550, dim=128, type=5
[ INFO] Creating vocabulary...
[ INFO] Object 1, 550 words from 550 descriptors (550 words, 0 ms)
[ INFO] Creating vocabulary... done! size=550 (6 ms)
[ INFO] TcpServer set on port: 6000 (IP=192.168.0.100)
[ INFO] TcpServer set on port: 6001 (IP=192.168.0.100)
[ INFO] TcpServer set on port: 6002 (IP=192.168.0.100)
[ INFO] TcpServer set on port: 6003 (IP=192.168.0.100)
Then you can do the request as above but using only "--port" argument:
./find_object-tcpRequest --json "out.json" --scene box_in_scene.png --port 6000
Using bidirectional port
Image published (365707 bytes), waiting for response...
Response received! (218 ms)
Object 1 detected.
JSON written to "out.json"
On computer 1 (where Find-Object will run, port 6000 is used to received images, port 7000 is used to output detection results):
# 192.168.0.2
./find_object --Camera/6useTcpCamera true \
--Camera/8port 6000 \
--General/autoStartCamera true \
--General/port 7000
On computer 2 (having a USB camera connected):
# 192.168.0.3
./find_object-tcpImagesServer --host 192.168.0.2 6000
On computer 3 (subscribe to detection results):
# 192.168.0.4
./find_object-tcpClient 192.168.0.2 7000