{
  "id": 161849,
  "title": "OpenCv Crash. cv2.imshow",
  "url": "/competitions/global-wheat-detection/discussion/161849",
  "author_name": "",
  "post_date": "2020-06-26T11:29:28.117200800Z",
  "votes": null,
  "comment_count": 2,
  "views": 0,
  "content": "<p>I am trying to edit images with OpenCV. I am simply trying to crop the image.I am able to do it with Matplotlib but I want to use OpenCv. When I excecute the code, it does not give me any message and it deletes all variables. It is like restarting the whole kernel. The varialbe img is not created and even variables created previously are deleted. Does anyone is experiencing the same problem?</p>\n\n<p>import cv2\nimport glob, pylab, pandas as pd\nimg = cv2.imread(\"/kaggle/input/global-wheat-detection/train/07479da31.jpg\")\ncrop_img = img[715:834, 108:176]\ncv2.imshow(\"cropped\", crop_img)\ncv2.waitKey(0)</p>",
  "messages": [
    {
      "id": "902813",
      "postDate": "06/26/2020 11:29:28",
      "content": "<p>I am trying to edit images with OpenCV. I am simply trying to crop the image.I am able to do it with Matplotlib but I want to use OpenCv. When I excecute the code, it does not give me any message and it deletes all variables. It is like restarting the whole kernel. The varialbe img is not created and even variables created previously are deleted. Does anyone is experiencing the same problem?</p>\n\n<p>import cv2\nimport glob, pylab, pandas as pd\nimg = cv2.imread(\"/kaggle/input/global-wheat-detection/train/07479da31.jpg\")\ncrop_img = img[715:834, 108:176]\ncv2.imshow(\"cropped\", crop_img)\ncv2.waitKey(0)</p>",
      "rawMarkdown": "I am trying to edit images with OpenCV. I am simply trying to crop the image.I am able to do it with Matplotlib but I want to use OpenCv. When I excecute the code, it does not give me any message and it deletes all variables. It is like restarting the whole kernel. The varialbe img is not created and even variables created previously are deleted. Does anyone is experiencing the same problem?\n\nimport cv2\nimport glob, pylab, pandas as pd\nimg = cv2.imread(\"/kaggle/input/global-wheat-detection/train/07479da31.jpg\")\ncrop_img = img[715:834, 108:176]\ncv2.imshow(\"cropped\", crop_img)\ncv2.waitKey(0)",
      "votes": null
    },
    {
      "id": "902843",
      "postDate": "06/26/2020 11:49:49",
      "content": "<p>I don't think you can use cv2.imshow in the notebooks environment. If I remember correctly, it used to depend on GTK to draw the image window.</p>\n\n<p>Are you avoiding the <code>plt.imshow</code> due to channel inversion?\nOpenCV favours BGR representation and matplotlib prefers RGB representation.\nIt is easily taken care of. 2 ways:</p>\n\n<ol>\n<li><p>Just use imageio (it reads in RGB) to read images, rest everything remains same:\n<code>\nimport imageio\nimg = imageio.imread(\"/kaggle/input/global-wheat-detection/train/07479da31.jpg\")\ncropimg = img[715:834, 108:176]\nplt.imshow(cropimg)\n</code></p></li>\n<li><p>Convert image from BGR to RGB before displaying:\n(Using your code)</p></li>\n</ol>\n\n<p><code>\nimport cv2\nimport glob, pylab, pandas as pd\nimg = cv2.imread(\"/kaggle/input/global-wheat-detection/train/07479da31.jpg\")\ncropimg = img[715:834, 108:176]\nplt.imshow(cv2.cvtColor(cropimg, cv2.COLOR_BGR2RGB))\n</code></p>",
      "rawMarkdown": "I don't think you can use cv2.imshow in the notebooks environment. If I remember correctly, it used to depend on GTK to draw the image window.\n\nAre you avoiding the `plt.imshow` due to channel inversion?\nOpenCV favours BGR representation and matplotlib prefers RGB representation.\nIt is easily taken care of. 2 ways:\n\n1.  Just use imageio (it reads in RGB) to read images, rest everything remains same:\n```\nimport imageio\nimg = imageio.imread(\"/kaggle/input/global-wheat-detection/train/07479da31.jpg\")\ncropimg = img[715:834, 108:176]\nplt.imshow(cropimg)\n```\n\n2. Convert image from BGR to RGB before displaying:\n(Using your code)\n\n```\nimport cv2\nimport glob, pylab, pandas as pd\nimg = cv2.imread(\"/kaggle/input/global-wheat-detection/train/07479da31.jpg\")\ncropimg = img[715:834, 108:176]\nplt.imshow(cv2.cvtColor(cropimg, cv2.COLOR_BGR2RGB))\n```",
      "votes": null
    },
    {
      "id": "916415",
      "postDate": "07/05/2020 16:01:36",
      "content": "<p><a href=\"/luisvivas\">@luisvivas</a> You can also use\nplt.imread() to read the image which read an image in RGB channel .</p>",
      "rawMarkdown": "luisvivas You can also use\nplt.imread() to read the image which read an image in RGB channel .",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 902843,
      "author_name": "mightyrains",
      "author_url": "",
      "post_date": "06/26/2020 11:49:49",
      "content": "<p>I don't think you can use cv2.imshow in the notebooks environment. If I remember correctly, it used to depend on GTK to draw the image window.</p>\n\n<p>Are you avoiding the <code>plt.imshow</code> due to channel inversion?\nOpenCV favours BGR representation and matplotlib prefers RGB representation.\nIt is easily taken care of. 2 ways:</p>\n\n<ol>\n<li><p>Just use imageio (it reads in RGB) to read images, rest everything remains same:\n<code>\nimport imageio\nimg = imageio.imread(\"/kaggle/input/global-wheat-detection/train/07479da31.jpg\")\ncropimg = img[715:834, 108:176]\nplt.imshow(cropimg)\n</code></p></li>\n<li><p>Convert image from BGR to RGB before displaying:\n(Using your code)</p></li>\n</ol>\n\n<p><code>\nimport cv2\nimport glob, pylab, pandas as pd\nimg = cv2.imread(\"/kaggle/input/global-wheat-detection/train/07479da31.jpg\")\ncropimg = img[715:834, 108:176]\nplt.imshow(cv2.cvtColor(cropimg, cv2.COLOR_BGR2RGB))\n</code></p>",
      "votes": null,
      "replies": [
        {
          "id": 916415,
          "author_name": "ravirajsinh45",
          "author_url": "",
          "post_date": "07/05/2020 16:01:36",
          "content": "<p><a href=\"/luisvivas\">@luisvivas</a> You can also use\nplt.imread() to read the image which read an image in RGB channel .</p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "902813": "I am trying to edit images with OpenCV. I am simply trying to crop the image.I am able to do it with Matplotlib but I want to use OpenCv. When I excecute the code, it does not give me any message and it deletes all variables. It is like restarting the whole kernel. The varialbe img is not created and even variables created previously are deleted. Does anyone is experiencing the same problem?\n\nimport cv2\nimport glob, pylab, pandas as pd\nimg = cv2.imread(\"/kaggle/input/global-wheat-detection/train/07479da31.jpg\")\ncrop_img = img[715:834, 108:176]\ncv2.imshow(\"cropped\", crop_img)\ncv2.waitKey(0)",
    "902843": "I don't think you can use cv2.imshow in the notebooks environment. If I remember correctly, it used to depend on GTK to draw the image window.\n\nAre you avoiding the `plt.imshow` due to channel inversion?\nOpenCV favours BGR representation and matplotlib prefers RGB representation.\nIt is easily taken care of. 2 ways:\n\n1.  Just use imageio (it reads in RGB) to read images, rest everything remains same:\n```\nimport imageio\nimg = imageio.imread(\"/kaggle/input/global-wheat-detection/train/07479da31.jpg\")\ncropimg = img[715:834, 108:176]\nplt.imshow(cropimg)\n```\n\n2. Convert image from BGR to RGB before displaying:\n(Using your code)\n\n```\nimport cv2\nimport glob, pylab, pandas as pd\nimg = cv2.imread(\"/kaggle/input/global-wheat-detection/train/07479da31.jpg\")\ncropimg = img[715:834, 108:176]\nplt.imshow(cv2.cvtColor(cropimg, cv2.COLOR_BGR2RGB))\n```",
    "916415": "luisvivas You can also use\nplt.imread() to read the image which read an image in RGB channel ."
  },
  "source": "meta"
}