# 1-Point perspective

<div><figure><img src="https://1051631996-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWpWB3PhSXYf1uN1tGGIQ%2Fuploads%2FXLEfX8Dwq5JfNpXYgKbN%2FScreenshot%202567-03-11%20at%2016.25.42.png?alt=media&#x26;token=e05bfbc6-6214-4fe0-8f7d-93767ba34edf" alt=""><figcaption><p>Before</p></figcaption></figure> <figure><img src="https://1051631996-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWpWB3PhSXYf1uN1tGGIQ%2Fuploads%2FdDDN4A1RME5V2GOMfRly%2FScreenshot%202567-03-11%20at%2016.25.00.png?alt=media&#x26;token=3f4d59a0-61a7-4f40-a44a-5b4689fc16c9" alt=""><figcaption><p>After</p></figcaption></figure></div>

## Description

Generate orthogonal lines on uploaded room images to assist with accurate dimension calculations and room sizing visualizations of a 1-point perspective room image.

## Use cases

1. Accurate space planning and furniture fitting.
2. Enhancing property listings with detailed room dimensions.

## Credit

1 successful Space Design API call = 1 credit.

## API

<mark style="color:green;">`POST`</mark> `https://api.spacely.ai/api/v1/generate/two-point-perspective`

This endpoint is used to advance generate

#### Headers

| Name                                        | Type   | Description |
| ------------------------------------------- | ------ | ----------- |
| X-API-KEY<mark style="color:red;">\*</mark> | String |             |

#### Request Body

| Name                                              | Type      | Description                                                                                                                                                                                                                                                                                                                                                                                |
| ------------------------------------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| imageUrl<mark style="color:red;">\*</mark>        | String    | <p>The URL of the image representing the room or space to visualize dimensions.</p><p>(e.g., "<a href="https://storage.googleapis.com/spacely/public/image/roomstyle3/bathroom-modern.jpg"><https://storage.googleapis.com/spacely/public/image/roomstyle3/bathroom-modern.jpg></a>").</p>                                                                                                 |
| topLeftLine<mark style="color:red;">\*</mark>     | Object\[] | <p>An array of 2 coordinate objects representing the line on the top left orthogonal line (the connecting line between wall and ceiling at the upper left hand side of the room).</p><p></p><p>Where the first element is the point that is deeper inside the room. The last element is nearer to the camera.</p><p></p><p>e.g. </p><p>\[{ "x": 0, "y": 0},{"x":100.2,"y":100.2}]</p>      |
| topRightLine<mark style="color:red;">\*</mark>    | Object\[] | <p>An array of 2 coordinate objects representing the line on the top right orthogonal line (the connecting line between wall and ceiling at the upper right hand side of the room).</p><p></p><p>Where the first element is the point that is deeper inside the room. The last element is nearer to the camera.</p><p></p><p>e.g. </p><p>\[{ "x": 0, "y": 0},{"x":100.2,"y":100.2}]</p>    |
| roomHeight<mark style="color:red;">\*</mark>      | Float     | The height of the room/space. Must be in meter.                                                                                                                                                                                                                                                                                                                                            |
| bottomLeftLine<mark style="color:red;">\*</mark>  | Object\[] | <p>An array of 2 coordinate objects representing the line on the bottom left orthogonal line (the connecting line between wall and ceiling at the lower left hand side of the room).</p><p></p><p>Where the first element is the point that is deeper inside the room. The last element is nearer to the camera.</p><p></p><p>e.g. </p><p>\[{ "x": 0, "y": 0},{"x":100.2,"y":100.2}]</p>   |
| bottomRightLine<mark style="color:red;">\*</mark> | Object\[] | <p>An array of 2 coordinate objects representing the line on the bottom right orthogonal line (the connecting line between wall and ceiling at the lower right hand side of the room).</p><p></p><p>Where the first element is the point that is deeper inside the room. The last element is nearer to the camera.</p><p></p><p>e.g. </p><p>\[{ "x": 0, "y": 0},{"x":100.2,"y":100.2}]</p> |
| roomWidth                                         | Float     | The width of the room/space. Must be in meter.                                                                                                                                                                                                                                                                                                                                             |
| referenceLine                                     | Object\[] | <p>An array of 2 coordinate objects representing the 1-meter line on the bottom right orthogonal line </p><p></p><p>Where the first element is the point that is deeper inside the room. The last element is 1 meter from the former.</p><p></p><p>e.g. </p><p>\[{ "x": 0, "y": 0},{"x":100.2,"y":100.2}]</p>                                                                              |

{% tabs %}
{% tab title="200: OK Response ref Id for pulling data" %}

```json
{
  "data": "63d17492-43d9-4161-0000-b067be1316dc"
}
```

{% endtab %}

{% tab title="400: Bad Request Not Found: Requested resource not found on the server." %}

{% endtab %}

{% tab title="401: Unauthorized The API key provided was invalid or missing." %}

{% endtab %}

{% tab title="500: Internal Server Error Unexpected condition on the server preventing request fulfillment." %}

{% endtab %}
{% endtabs %}

## Example

{% tabs %}
{% tab title="cURL" %}

```sh
curl --location 'https://api.spacely.ai/api/v1/generate/one-point-perspective' \
--header 'X-API-KEY: YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data '{
    "imageUrl": "IMAGE_URL",
    "topLeftLine": [
        {
            "x": 68.57142857142857,
            "y": 28.4534351245777
        },
        {
            "x": 33.38345864661654,
            "y": -0.3753937042511261
        }
    ],
    "topRightLine": [
        {
            "x": 520.6015037593985,
            "y": 28.716216216216218
        },
        {
            "x": 555.7894736842105,
            "y": 0.7882882882882883
        }
    ],
    "bottomLeftLine": [
        {
            "x": 65.86466165413533,
            "y": 300.45045045045043
        },
        {
            "x": 0,
            "y": 340.0900900900901
        }
    ],
    "bottomRightLine": [
        {
            "x": 521.5037593984962,
            "y": 297.1095729518581
        },
        {
            "x": 599.0977443609023,
            "y": 352.06452790681305
        }
    ],
    "referenceLine": [
        {
            "x": 520.6015037593985,
            "y": 301.20118287232543
        },
        {
            "x": 572.0300751879699,
            "y": 334.5345162056588
        }
    ],
    "roomHeight": 3,
    "roomWidth": 4
}'

```

{% endtab %}

{% tab title="JavaScript  " %}

```javascript
const myHeaders = new Headers();
myHeaders.append("X-API-KEY", "YOUR_API_KEY");
myHeaders.append("Content-Type", "application/json");

const raw = JSON.stringify({
  "imageUrl": "IMAGE_URL",
  "topLeftLine": [
    {
      "x": 68.57142857142857,
      "y": 28.4534351245777
    },
    {
      "x": 33.38345864661654,
      "y": -0.3753937042511261
    }
  ],
  "topRightLine": [
    {
      "x": 520.6015037593985,
      "y": 28.716216216216218
    },
    {
      "x": 555.7894736842105,
      "y": 0.7882882882882883
    }
  ],
  "bottomLeftLine": [
    {
      "x": 65.86466165413533,
      "y": 300.45045045045043
    },
    {
      "x": 0,
      "y": 340.0900900900901
    }
  ],
  "bottomRightLine": [
    {
      "x": 521.5037593984962,
      "y": 297.1095729518581
    },
    {
      "x": 599.0977443609023,
      "y": 352.06452790681305
    }
  ],
  "referenceLine": [
    {
      "x": 520.6015037593985,
      "y": 301.20118287232543
    },
    {
      "x": 572.0300751879699,
      "y": 334.5345162056588
    }
  ],
  "roomHeight": 3,
  "roomWidth": 4
});

const requestOptions = {
  method: "POST",
  headers: myHeaders,
  body: raw,
  redirect: "follow"
};

fetch("https://api.spacely.ai/api/v1/generate/one-point-perspective", requestOptions)
  .then((response) => response.text())
  .then((result) => console.log(result))
  .catch((error) => console.error(error));
```

{% endtab %}

{% tab title="NodeJs" %}

```javascript
const axios = require('axios');
let data = JSON.stringify({
  "imageUrl": "IMAGE_URL",
  "topLeftLine": [
    {
      "x": 68.57142857142857,
      "y": 28.4534351245777
    },
    {
      "x": 33.38345864661654,
      "y": -0.3753937042511261
    }
  ],
  "topRightLine": [
    {
      "x": 520.6015037593985,
      "y": 28.716216216216218
    },
    {
      "x": 555.7894736842105,
      "y": 0.7882882882882883
    }
  ],
  "bottomLeftLine": [
    {
      "x": 65.86466165413533,
      "y": 300.45045045045043
    },
    {
      "x": 0,
      "y": 340.0900900900901
    }
  ],
  "bottomRightLine": [
    {
      "x": 521.5037593984962,
      "y": 297.1095729518581
    },
    {
      "x": 599.0977443609023,
      "y": 352.06452790681305
    }
  ],
  "referenceLine": [
    {
      "x": 520.6015037593985,
      "y": 301.20118287232543
    },
    {
      "x": 572.0300751879699,
      "y": 334.5345162056588
    }
  ],
  "roomHeight": 3,
  "roomWidth": 4
});

let config = {
  method: 'post',
  maxBodyLength: Infinity,
  url: 'https://api.spacely.ai/api/v1/generate/one-point-perspective',
  headers: { 
    'X-API-KEY': 'YOUR_API_KEY', 
    'Content-Type': 'application/json'
  },
  data : data
};

axios.request(config)
.then((response) => {
  console.log(JSON.stringify(response.data));
})
.catch((error) => {
  console.log(error);
});


```

{% endtab %}

{% tab title="Go" %}

```go
package main

import (
  "fmt"
  "strings"
  "net/http"
  "io/ioutil"
)

func main() {

  url := "https://api.spacely.ai/api/v1/generate/one-point-perspective"
  method := "POST"

  payload := strings.NewReader(`{
    "imageUrl": "IMAGE_URL",
    "topLeftLine": [
        {
            "x": 68.57142857142857,
            "y": 28.4534351245777
        },
        {
            "x": 33.38345864661654,
            "y": -0.3753937042511261
        }
    ],
    "topRightLine": [
        {
            "x": 520.6015037593985,
            "y": 28.716216216216218
        },
        {
            "x": 555.7894736842105,
            "y": 0.7882882882882883
        }
    ],
    "bottomLeftLine": [
        {
            "x": 65.86466165413533,
            "y": 300.45045045045043
        },
        {
            "x": 0,
            "y": 340.0900900900901
        }
    ],
    "bottomRightLine": [
        {
            "x": 521.5037593984962,
            "y": 297.1095729518581
        },
        {
            "x": 599.0977443609023,
            "y": 352.06452790681305
        }
    ],
    "referenceLine": [
        {
            "x": 520.6015037593985,
            "y": 301.20118287232543
        },
        {
            "x": 572.0300751879699,
            "y": 334.5345162056588
        }
    ],
    "roomHeight": 3,
    "roomWidth": 4
}`)

  client := &http.Client {
  }
  req, err := http.NewRequest(method, url, payload)

  if err != nil {
    fmt.Println(err)
    return
  }
  req.Header.Add("X-API-KEY", "YOUR_API_KEY")
  req.Header.Add("Content-Type", "application/json")

  res, err := client.Do(req)
  if err != nil {
    fmt.Println(err)
    return
  }
  defer res.Body.Close()

  body, err := ioutil.ReadAll(res.Body)
  if err != nil {
    fmt.Println(err)
    return
  }
  fmt.Println(string(body))
}
```

{% endtab %}

{% tab title="Python" %}

```python
import requests
import json

url = "https://api.spacely.ai/api/v1/generate/one-point-perspective"

payload = json.dumps({
  "imageUrl": "IMAGE_URL",
  "topLeftLine": [
    {
      "x": 68.57142857142857,
      "y": 28.4534351245777
    },
    {
      "x": 33.38345864661654,
      "y": -0.3753937042511261
    }
  ],
  "topRightLine": [
    {
      "x": 520.6015037593985,
      "y": 28.716216216216218
    },
    {
      "x": 555.7894736842105,
      "y": 0.7882882882882883
    }
  ],
  "bottomLeftLine": [
    {
      "x": 65.86466165413533,
      "y": 300.45045045045043
    },
    {
      "x": 0,
      "y": 340.0900900900901
    }
  ],
  "bottomRightLine": [
    {
      "x": 521.5037593984962,
      "y": 297.1095729518581
    },
    {
      "x": 599.0977443609023,
      "y": 352.06452790681305
    }
  ],
  "referenceLine": [
    {
      "x": 520.6015037593985,
      "y": 301.20118287232543
    },
    {
      "x": 572.0300751879699,
      "y": 334.5345162056588
    }
  ],
  "roomHeight": 3,
  "roomWidth": 4
})
headers = {
  'X-API-KEY': 'YOUR_API_KEY',
  'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)
```

{% endtab %}
{% endtabs %}

## Support

Any question? Contact us at <support@spacely.ai>
