# 2-Point perspective

<div><figure><img src="https://1051631996-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWpWB3PhSXYf1uN1tGGIQ%2Fuploads%2FzOZY8hGTwHJtGBBQqvMB%2Finput.jpeg?alt=media&#x26;token=36b3e120-3e9c-4126-bc76-d107648d5b1d" 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%2FHl0YchiNszsfOwFsNaZj%2Foutput.jpeg?alt=media&#x26;token=b0491b42-9b7c-43c4-b90a-9665580f42f9" 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 2-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>                                                                                                                                                                                                                                  |
| topCornerLine<mark style="color:red;">\*</mark>             | Object\[] | <p>An array of 3 coordinate objects.</p><p>Each object represents a critical corner point in sequence from left to right: the top-left corner, an intermediary corner point (if the wall is not straight), and the top-right corner.</p><p></p><p>e.g. </p><p>\[{ "x": 0, "y": 0},{"x":100.2,"y":100.2},</p><p>{"x": 200, "y": 200}]</p>                                                                                                                                                                                    |
| bottomCornerReferenceLine<mark style="color:red;">\*</mark> | Object\[] | an array of 3 coordinate objects. Unlike the `topCornerLine`, the points provided here are not the actual corners of the room. Instead, each coordinate marks a point on the bottom boundary line of the room, where the distance to the actual corner is exactly 1 meter towards the center of the room. The sequence is from left to right: a point near the bottom-left corner, a middle reference point (usually at or close to the actual middle bottom corner of the room), and a point near the bottom-right corner. |
| roomHeight<mark style="color:red;">\*</mark>                | Float     | The height of the room/space. Must be in meter.                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |

{% 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/two-point-perspective' \
--header 'X-API-KEY: YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data '{
    "imageUrl": "IMAGE_URL",
    "topCornerLine": [
        {
            "x": -3.094736842105263,
            "y": 75.64426697406572
        },
        {
            "x": 420.88421052631577,
            "y": 157.60302986066367
        },
        {
            "x": 1022.8105263157895,
            "y": 89.56179274726159
        }
    ],
    "bottomCornerReferenceLine": [
        {
            "x": 250.67368421052632,
            "y": 587.7577004973422
        },
        {
            "x": 428.62105263157895,
            "y": 561.4690407035278
        },
        {
            "x": 603.4736842105264,
            "y": 571.2628708672278
        }
    ],
    "roomHeight": 3
}'
```

{% 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",
  "topCornerLine": [
    {
      "x": -3.094736842105263,
      "y": 75.64426697406572
    },
    {
      "x": 420.88421052631577,
      "y": 157.60302986066367
    },
    {
      "x": 1022.8105263157895,
      "y": 89.56179274726159
    }
  ],
  "bottomCornerReferenceLine": [
    {
      "x": 250.67368421052632,
      "y": 587.7577004973422
    },
    {
      "x": 428.62105263157895,
      "y": 561.4690407035278
    },
    {
      "x": 603.4736842105264,
      "y": 571.2628708672278
    }
  ],
  "roomHeight": 3
});

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

fetch("https://api.spacely.ai/api/v1/generate/two-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",
  "topCornerLine": [
    {
      "x": -3.094736842105263,
      "y": 75.64426697406572
    },
    {
      "x": 420.88421052631577,
      "y": 157.60302986066367
    },
    {
      "x": 1022.8105263157895,
      "y": 89.56179274726159
    }
  ],
  "bottomCornerReferenceLine": [
    {
      "x": 250.67368421052632,
      "y": 587.7577004973422
    },
    {
      "x": 428.62105263157895,
      "y": 561.4690407035278
    },
    {
      "x": 603.4736842105264,
      "y": 571.2628708672278
    }
  ],
  "roomHeight": 3
});

let config = {
  method: 'post',
  maxBodyLength: Infinity,
  url: 'https://api.spacely.ai/api/v1/generate/two-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/two-point-perspective"
  method := "POST"

  payload := strings.NewReader(`{
    "imageUrl": "IMAGE_URL",
    "topCornerLine": [
        {
            "x": -3.094736842105263,
            "y": 75.64426697406572
        },
        {
            "x": 420.88421052631577,
            "y": 157.60302986066367
        },
        {
            "x": 1022.8105263157895,
            "y": 89.56179274726159
        }
    ],
    "bottomCornerReferenceLine": [
        {
            "x": 250.67368421052632,
            "y": 587.7577004973422
        },
        {
            "x": 428.62105263157895,
            "y": 561.4690407035278
        },
        {
            "x": 603.4736842105264,
            "y": 571.2628708672278
        }
    ],
    "roomHeight": 3
}`)

  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/two-point-perspective"

payload = json.dumps({
  "imageUrl": "IMAGE_URL",
  "topCornerLine": [
    {
      "x": -3.094736842105263,
      "y": 75.64426697406572
    },
    {
      "x": 420.88421052631577,
      "y": 157.60302986066367
    },
    {
      "x": 1022.8105263157895,
      "y": 89.56179274726159
    }
  ],
  "bottomCornerReferenceLine": [
    {
      "x": 250.67368421052632,
      "y": 587.7577004973422
    },
    {
      "x": 428.62105263157895,
      "y": 561.4690407035278
    },
    {
      "x": 603.4736842105264,
      "y": 571.2628708672278
    }
  ],
  "roomHeight": 3
})
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>
