{
  "id": 225462,
  "title": "cv2.fillPoly crash on the new json mask data",
  "url": "/competitions/hubmap-kidney-segmentation/discussion/225462",
  "author_name": "",
  "post_date": "2021-03-12T11:33:36.585826300Z",
  "votes": null,
  "comment_count": 2,
  "views": 0,
  "content": "<p>Hi,</p>\n<p>I've observed a crash on cv2.fillPoly call when using it with the new train data.<br>\nI used the following code to read json masks:</p>\n<p>def read_mask(mask_file, mask_shape):<br>\n    read_file = open(mask_file, \"r\") <br>\n    mask_data = json.load(read_file)<br>\n    polys = []<br>\n    for index in range(mask_data.<strong>len</strong>()):<br>\n        geom = np.array(mask_data[index]['geometry']['coordinates'])<br>\n        polys.append(geom)<br>\n    mask = np.zeros(mask_shape, dtype=np.uint8)<br>\n    cv2.fillPoly(mask, polys, 1)</p>\n<p>This code works fine with an old data. With new, it crashes with error:</p>\n<p>error: OpenCV(4.4.0) /tmp/pip-req-build-dglzv4yn/opencv/modules/imgproc/src/drawing.cpp:2395: error: (-215:Assertion failed) p.checkVector(2, CV_32S) &gt;= 0 in function 'fillPoly'</p>\n<p>Do anybody observed a behavior like this after update?<br>\nAny hints?</p>\n<p>Thanks in advance!</p>",
  "messages": [
    {
      "id": "1235683",
      "postDate": "03/12/2021 11:33:36",
      "content": "<p>Hi,</p>\n<p>I've observed a crash on cv2.fillPoly call when using it with the new train data.<br>\nI used the following code to read json masks:</p>\n<p>def read_mask(mask_file, mask_shape):<br>\n    read_file = open(mask_file, \"r\") <br>\n    mask_data = json.load(read_file)<br>\n    polys = []<br>\n    for index in range(mask_data.<strong>len</strong>()):<br>\n        geom = np.array(mask_data[index]['geometry']['coordinates'])<br>\n        polys.append(geom)<br>\n    mask = np.zeros(mask_shape, dtype=np.uint8)<br>\n    cv2.fillPoly(mask, polys, 1)</p>\n<p>This code works fine with an old data. With new, it crashes with error:</p>\n<p>error: OpenCV(4.4.0) /tmp/pip-req-build-dglzv4yn/opencv/modules/imgproc/src/drawing.cpp:2395: error: (-215:Assertion failed) p.checkVector(2, CV_32S) &gt;= 0 in function 'fillPoly'</p>\n<p>Do anybody observed a behavior like this after update?<br>\nAny hints?</p>\n<p>Thanks in advance!</p>",
      "rawMarkdown": "Hi,\n\nI've observed a crash on cv2.fillPoly call when using it with the new train data.\nI used the following code to read json masks:\n\ndef read_mask(mask_file, mask_shape):\n    read_file = open(mask_file, \"r\") \n    mask_data = json.load(read_file)\n    polys = []\n    for index in range(mask_data.__len__()):\n        geom = np.array(mask_data[index]['geometry']['coordinates'])\n        polys.append(geom)\n    mask = np.zeros(mask_shape, dtype=np.uint8)\n    cv2.fillPoly(mask, polys, 1)\n\nThis code works fine with an old data. With new, it crashes with error:\n\nerror: OpenCV(4.4.0) /tmp/pip-req-build-dglzv4yn/opencv/modules/imgproc/src/drawing.cpp:2395: error: (-215:Assertion failed) p.checkVector(2, CV_32S) >= 0 in function 'fillPoly'\n\nDo anybody observed a behavior like this after update?\nAny hints?\n\nThanks in advance!",
      "votes": null
    },
    {
      "id": "1235717",
      "postDate": "03/12/2021 12:05:49",
      "content": "<p>geom = np.array(mask_data[index]['geometry']['coordinates'])<strong>.astype(np.int32)</strong> should fix this issue</p>",
      "rawMarkdown": "geom = np.array(mask_data[index]['geometry']['coordinates'])**.astype(np.int32)** should fix this issue",
      "votes": null
    },
    {
      "id": "1235815",
      "postDate": "03/12/2021 13:48:18",
      "content": "<p>Thanks a lot, Ilia, it works!<br>\nAlso I find an answer in this <a href=\"https://www.kaggle.com/mpware/masks-quick-eda-updated-data/notebook.\" target=\"_blank\">excellent notebook</a></p>",
      "rawMarkdown": "Thanks a lot, Ilia, it works!\nAlso I find an answer in this [excellent notebook](https://www.kaggle.com/mpware/masks-quick-eda-updated-data/notebook.)",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1235717,
      "author_name": "tetelias",
      "author_url": "",
      "post_date": "03/12/2021 12:05:49",
      "content": "<p>geom = np.array(mask_data[index]['geometry']['coordinates'])<strong>.astype(np.int32)</strong> should fix this issue</p>",
      "votes": null,
      "replies": [
        {
          "id": 1235815,
          "author_name": "polishch",
          "author_url": "",
          "post_date": "03/12/2021 13:48:18",
          "content": "<p>Thanks a lot, Ilia, it works!<br>\nAlso I find an answer in this <a href=\"https://www.kaggle.com/mpware/masks-quick-eda-updated-data/notebook.\" target=\"_blank\">excellent notebook</a></p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "1235683": "Hi,\n\nI've observed a crash on cv2.fillPoly call when using it with the new train data.\nI used the following code to read json masks:\n\ndef read_mask(mask_file, mask_shape):\n    read_file = open(mask_file, \"r\") \n    mask_data = json.load(read_file)\n    polys = []\n    for index in range(mask_data.__len__()):\n        geom = np.array(mask_data[index]['geometry']['coordinates'])\n        polys.append(geom)\n    mask = np.zeros(mask_shape, dtype=np.uint8)\n    cv2.fillPoly(mask, polys, 1)\n\nThis code works fine with an old data. With new, it crashes with error:\n\nerror: OpenCV(4.4.0) /tmp/pip-req-build-dglzv4yn/opencv/modules/imgproc/src/drawing.cpp:2395: error: (-215:Assertion failed) p.checkVector(2, CV_32S) >= 0 in function 'fillPoly'\n\nDo anybody observed a behavior like this after update?\nAny hints?\n\nThanks in advance!",
    "1235717": "geom = np.array(mask_data[index]['geometry']['coordinates'])**.astype(np.int32)** should fix this issue",
    "1235815": "Thanks a lot, Ilia, it works!\nAlso I find an answer in this [excellent notebook](https://www.kaggle.com/mpware/masks-quick-eda-updated-data/notebook.)"
  },
  "source": "meta"
}