# Vehicle position detection using picture

**URL:** <https://discourse.nodered.org/t/vehicle-position-detection-using-picture/80441>\
**Category:** General\
**Created:** [9 August 2023 14:04 UTC](https://discourse.nodered.org/t/vehicle-position-detection-using-picture/80441 "2023-08-09T14:04:18Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![jttjtt](https://avatars.discourse-cdn.com/v4/letter/j/278dde/32.png) [@jttjtt](https://discourse.nodered.org/u/jttjtt)\
**Post date:** [9 August 2023 14:04 UTC](https://discourse.nodered.org/t/vehicle-position-detection-using-picture/80441/1 "2023-08-09T14:04:18Z")

</div>

Hello i am wondering, if there is some module in node red how can I check the vehicle position using a picture. So the process will be, that I have a picture of a vehicle for example from parking lot and i need to check, if the vehicle is parked within a defined area (some rectangle area for example).  
I just need to output some true/false value - if it is within a selected area or not. Thanks for help.

---

<div class="post-metadata">

**Author:** ![FireWizard52](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/firewizard52/32/34508_2.png) [@FireWizard52](https://discourse.nodered.org/u/FireWizard52)\
**Post date:** [9 August 2023 14:16 UTC](https://discourse.nodered.org/t/vehicle-position-detection-using-picture/80441/2 "2023-08-09T14:16:24Z")

</div>

Hello @jttjtt,

I think that it is possible with a node, called tensorflow.  
See: [node-red-contrib-tensorflow (node) - Node-RED](https://flows.nodered.org/node/node-red-contrib-tensorflow)  
Or any other equivalent.

An example picture below:

 ![Screenshot_tensorflow_car_detect](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/d/ad3eed1772435b48ef8df0ebe4cbf305c8549119.png)

It can detect vehicles in the picture and with the bounding box, you can compare, if it is in a certain position. Just an idea.

The msg result, see below:

 ![Screenshot_tensorflow_car_detect_debug](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/1/91e531c08d54510c460b8f9fee82da7c7d71d5e7.png)

Regards

---

<div class="post-metadata">

**Author:** ![jttjtt](https://avatars.discourse-cdn.com/v4/letter/j/278dde/32.png) [@jttjtt](https://discourse.nodered.org/u/jttjtt)\
**Post date:** [9 August 2023 14:28 UTC](https://discourse.nodered.org/t/vehicle-position-detection-using-picture/80441/3 "2023-08-09T14:28:12Z")

</div>

Great, thanks for the idea. This is what i wanted. I will test it if it works like i need.

---

<div class="post-metadata">

**Author:** ![PdeJ](https://avatars.discourse-cdn.com/v4/letter/p/c89c15/32.png) [@PdeJ](https://discourse.nodered.org/u/PdeJ)\
**Post date:** [9 August 2023 16:00 UTC](https://discourse.nodered.org/t/vehicle-position-detection-using-picture/80441/4 "2023-08-09T16:00:53Z")

</div>

Also more information here [Introduction - Node-RED AI Photo Booth Workshop](https://knolleary.net/node-red-workshop-photobooth/part3/index.html)

---

<div class="post-metadata">

**Author:** ![jttjtt](https://avatars.discourse-cdn.com/v4/letter/j/278dde/32.png) [@jttjtt](https://discourse.nodered.org/u/jttjtt)\
**Post date:** [23 August 2023 11:40 UTC](https://discourse.nodered.org/t/vehicle-position-detection-using-picture/80441/5 "2023-08-23T11:40:50Z")

</div>

![testauto2h](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/2/82c626d0883589f995312e18aa608862d35f05cb.jpeg)  
I woud like to ask - using the tensorflow module i was able to detect car in the picture. The output of bbox was:

0: 454.5329475402832  
1: 397.44991421699524  
2: 366.7844009399414  
3: 491.7205274105072

But i am not sure, what are these coordinates? I have found, that 0 and 1 should be X and Y coordinates and 2 and 3 should be widht and height. But when I open the picture i get different X,Y coordinates of the yellow area... Do I have right information? Thanks.

---

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [23 August 2023 17:38 UTC](https://discourse.nodered.org/t/vehicle-position-detection-using-picture/80441/6 "2023-08-23T17:38:14Z")

</div>

Hi,  
The bbox numbers can mean lots of things, depending on how the node developer has implemented it. E.g. the coordinates of the center point of the bbox. And sometimes the x and y coordinates, or width and height are switched. It can also be that it are the coordinates of the resized image. Suppose you inject an image with resolution NxM but the tensorflow model expects AxB. Then the input image will be resized to AxB, so tensorflow will calculate bounding boxes for that resized image, not for your original image...  
Bart

---

<div class="post-metadata">

**Author:** ![FireWizard52](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/firewizard52/32/34508_2.png) [@FireWizard52](https://discourse.nodered.org/u/FireWizard52)\
**Post date:** [24 August 2023 17:39 UTC](https://discourse.nodered.org/t/vehicle-position-detection-using-picture/80441/7 "2023-08-24T17:39:46Z")

</div>

Hi, @jttjtt

As far as I'm aware for Node RED and the Tensorflow node the bbox array represent the x, y co-ordinates and the width and height as follows: [x,y,w,h], all floats, but as Bart says, that will also depend on the resolution of the picture.

But, if I'm wrong, please correct me.

Which different values do you get?

Regards

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [24 August 2023 23:14 UTC](https://discourse.nodered.org/t/vehicle-position-detection-using-picture/80441/8 "2023-08-24T23:14:12Z")

</div>

I hope this is not for issuing parking fines 🙄

---

<div class="post-metadata">

**Author:** ![jttjtt](https://avatars.discourse-cdn.com/v4/letter/j/278dde/32.png) [@jttjtt](https://discourse.nodered.org/u/jttjtt)\
**Post date:** [25 August 2023 05:55 UTC](https://discourse.nodered.org/t/vehicle-position-detection-using-picture/80441/9 "2023-08-25T05:55:55Z")

</div>

@Sean-McG - no, this it not the purpose 🙂 We need to just check, if the car/truck is parked in the same area each time. So we have a rectangle area and I want to know, if the car is "inside" this area.

@FireWizard52 I made picture of the car in the same location four times and get these outputs:

test1  
0: 457.0689010620117  
1: 397.5502395629883  
2: 371.5623092651367  
3: 493.79176139831543

test2  
0: 454.5329475402832  
1: 397.44991421699524  
2: 366.7844009399414  
3: 491.7205274105072

test3  
0: 452.34094619750977  
1: 395.6010568141937  
2: 377.09049224853516  
3: 493.55998635292053

test4  
0: 460.2616882324219  
1: 390.64797163009644  
2: 365.2397918701172  
3: 498.88250827789307

Then I put the car around 60cm back and got these outputs:

0: 493.72135162353516  
1: 358.54965448379517  
2: 354.7510528564453  
3: 494.5740222930908

take 2  
0: 494.813232421875  
1: 359.90325808525085  
2: 357.15396881103516  
3: 497.2400629520416

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [25 August 2023 06:09 UTC](https://discourse.nodered.org/t/vehicle-position-detection-using-picture/80441/10 "2023-08-25T06:09:49Z")

</div>

So you just have to define allowed value intervals for each, then you create a "allowance zone" and as long as all values are within their respective allowed interval, the truck is parked correctly

EDIT: Like x is valid within 450 +/- 50 or so, y 390 +/- 50 etc and then fine tune if required

---

<div class="post-metadata">

**Author:** ![jttjtt](https://avatars.discourse-cdn.com/v4/letter/j/278dde/32.png) [@jttjtt](https://discourse.nodered.org/u/jttjtt)\
**Post date:** [25 August 2023 09:34 UTC](https://discourse.nodered.org/t/vehicle-position-detection-using-picture/80441/11 "2023-08-25T09:34:16Z")

</div>

![testauto2h1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/9/09fdf8d59e6d4b9cc130737e285487d0b2a6b80c.jpeg)

So the coordinates should be like this?

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [25 August 2023 11:16 UTC](https://discourse.nodered.org/t/vehicle-position-detection-using-picture/80441/12 "2023-08-25T11:16:59Z")

</div>

I think so, looks ok to me

---

<div class="post-metadata">

**Author:** ![FireWizard52](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/firewizard52/32/34508_2.png) [@FireWizard52](https://discourse.nodered.org/u/FireWizard52)\
**Post date:** [26 August 2023 16:31 UTC](https://discourse.nodered.org/t/vehicle-position-detection-using-picture/80441/13 "2023-08-26T16:31:36Z")

</div>

Hello @jttjtt

I do not understand why you have 4 different bbox values. I tested it several times with my example from my first post and got always exactly the same value. So the tensorflow output is stable (as expected). It may only happen, if you use 4 different pictures as input and I believe you do. So you need some tolerance, as Walter already suggested. The value you have to sort out by trial and error, I think This defines your "allowance zone" or even multiple zones.

You may want to try to find the correct "allowance zone" by using this node: [node-red-node-annotate-image (node) - Node-RED](https://flows.nodered.org/node/node-red-node-annotate-image)

You can insert possible values and on an empty picture, you can see how it looks like.  
See the example below:

 ![Screenshot_annotated image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/8/a80d80021be7d48ef84f8ff9bd6ec589d13489bd.png)

The upper "custom" node will give you some information about the image size, which is in my case 1600 x 800. See: [node-red-contrib-image-info (node) - Node-RED](https://flows.nodered.org/node/node-red-contrib-image-info/in/s8O6WWoGSyWu)

In the Function node you can configure the object, you want to annotate.  
I have chosen a quite thick (red) line in order to make it clearer in this picture.

See the result below:

 ![Screenshot_annotated image_result](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/f/1fa894eea7686ec0be363d1795ba7f837b013381.png)

If you want to try it yourself, please find this test flow below:

```auto
[{"id":"8fdeb0421bcbac9d","type":"annotate-image","z":"39005939.ba6f4e","name":"Image annotated","fill":"","stroke":"#ffC000","lineWidth":5,"fontSize":24,"fontColor":"#ffC000","x":1910,"y":1560,"wires":[["8f1691d13d3e7b82","0c1dc3f405a22867"]]},{"id":"8f1691d13d3e7b82","type":"debug","z":"39005939.ba6f4e","name":"Msg 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":2110,"y":1560,"wires":[]},{"id":"32be6079786d212e","type":"fileinject","z":"39005939.ba6f4e","name":"http://192.168.10.1","x":1490,"y":1520,"wires":[["a1020fafe390e963","9c6d86b90cf53489"]]},{"id":"0c1dc3f405a22867","type":"image","z":"39005939.ba6f4e","name":"Image Preview","width":160,"data":"payload","dataType":"msg","thumbnail":false,"active":true,"pass":false,"outputs":0,"x":2140,"y":1620,"wires":[]},{"id":"a1020fafe390e963","type":"function","z":"39005939.ba6f4e","name":"function 1","func":"msg.annotations = [\n {\n type: \"rect\",\n bbox: [300,400,1000,400],\n stroke: \"red\",\n lineWidth: 50\n }\n]\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1700,"y":1560,"wires":[["8fdeb0421bcbac9d"]]},{"id":"9c6d86b90cf53489","type":"image-info","z":"39005939.ba6f4e","name":"","x":1890,"y":1500,"wires":[["434311fc31b3fccd"]]},{"id":"434311fc31b3fccd","type":"debug","z":"39005939.ba6f4e","name":"Msg 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":2110,"y":1500,"wires":[]}]

```

Regards

---

<div class="post-metadata">

**Author:** ![jttjtt](https://avatars.discourse-cdn.com/v4/letter/j/278dde/32.png) [@jttjtt](https://discourse.nodered.org/u/jttjtt)\
**Post date:** [26 August 2023 17:42 UTC](https://discourse.nodered.org/t/vehicle-position-detection-using-picture/80441/14 "2023-08-26T17:42:23Z")

</div>

Thanks a lot. I Will try your solution. I got different outputs, because the input was always real picture from the onvif camera node. So there was still the same Car in the same position in the picture but the picture was taken everytime from the Onvif node. So it should be a bit different.

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [27 August 2023 05:38 UTC](https://discourse.nodered.org/t/vehicle-position-detection-using-picture/80441/15 "2023-08-27T05:38:44Z")

</div>

> [@FireWizard52](#):
>
> I do not understand why you have 4 different bbox values

For me it is also different values when the image is from a live camera. I assume it could be small changes in light conditions or background that triggers the tensorflow slightly different. Like in the example below, I can see the box moves a bit around my car when images are coming in

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/0/e03d88277e5d67fa60442ab820beee70353e30bf.png)

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [27 August 2023 08:24 UTC](https://discourse.nodered.org/t/vehicle-position-detection-using-picture/80441/16 "2023-08-27T08:24:34Z")

</div>

Just some further playing for fun, checking that my car is still there 😉

In the function node I'm setting up the bounderies fro my "allowed zone". Then on incoming messages I check that each corner of the bbox is within the zone. If so, car is parked correctly and still there

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/6/c6bc3d1f0a00d4eba637a3e4d107b71328e9d872.png)

This is the simple code in my function node, most likely room for improvements and further add-on ideas

```auto
if (msg.payload[0] == undefined){
    //node.warn('nothing');
    return; 
}

if (msg.payload[0]['class'] == 'car'){
    let x = [-5,10];
    let y = [25,75];
    let w = [275,325];
    let h = [250,350];
    let bbox = msg.payload[0]['bbox'];
    let cntr = 0
    if (bbox[0] > x[0] && bbox[0] < x[1] ){
        cntr += 1;
    }
    if (bbox[1] > y[0] && bbox[1] < y[1]) {
        cntr += 1;
    }
    if (bbox[2] > w[0] && bbox[2] < w[1]) {
        cntr += 1;
    }
    if (bbox[3] > h[0] && bbox[3] < h[1]) {
        cntr += 1;
    }
    if (cntr == 4){
        node.warn(bbox);
        node.warn('inside zone');
    } else {
        node.warn(bbox);
        node.warn('outside zone');
    }
}

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [26 October 2023 08:24 UTC](https://discourse.nodered.org/t/vehicle-position-detection-using-picture/80441/17 "2023-10-26T08:24:39Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
