Image loaded wrong by opencv The Next CEO of Stack OverflowHow to sharpen an image in OpenCV?Simple Digit Recognition OCR in OpenCV-PythonSave plot to image file instead of displaying it using MatplotlibImage Processing: Algorithm Improvement for 'Coca-Cola Can' RecognitionChecking images for similarity with OpenCVHow to crop an image in OpenCV using PythonSubtracting Background From Image using Opencv in PythonOpenCV giving wrong color to colored images on loadingOpenCV python layer is not working with caffe/digits frameworkDjango python-accept two images from post method, combine those images in opencv and then json response the final image

How do we know the LHC results are robust?

How should I support this large drywall patch?

Opposite of a diet

What does "Its cash flow is deeply negative" mean?

How to make a software documentation "officially" citable?

How did people program for Consoles with multiple CPUs?

Implement the Thanos sorting algorithm

Describing a person. What needs to be mentioned?

Is it safe to use c_str() on a temporary string?

Why did we only see the N-1 starfighters in one film?

Can a caster that cast Polymorph on themselves stop concentrating at any point even if their Int is low?

How can I get through very long and very dry, but also very useful technical documents when learning a new tool?

How to Reset Passwords on Multiple Websites Easily?

Anatomically Correct Mesopelagic Aves

When Does an Atlas Uniquely Define a Manifold?

How to make a variable always equal to the result of some calculations?

How to start emacs in "nothing" mode (`fundamental-mode`)

Can a single photon have an energy density?

How can I open an app using Terminal?

How to use tikz in fbox?

Why doesn't a table tennis ball float on the surface? How do we calculate buoyancy here?

Need some help with wall behind rangetop

If I blow insulation everywhere in my attic except the door trap, will heat escape through it?

Would this house-rule that treats advantage as a +1 to the roll instead (and disadvantage as -1) and allows them to stack be balanced?



Image loaded wrong by opencv



The Next CEO of Stack OverflowHow to sharpen an image in OpenCV?Simple Digit Recognition OCR in OpenCV-PythonSave plot to image file instead of displaying it using MatplotlibImage Processing: Algorithm Improvement for 'Coca-Cola Can' RecognitionChecking images for similarity with OpenCVHow to crop an image in OpenCV using PythonSubtracting Background From Image using Opencv in PythonOpenCV giving wrong color to colored images on loadingOpenCV python layer is not working with caffe/digits frameworkDjango python-accept two images from post method, combine those images in opencv and then json response the final image










0















Disaster!
enter image description here



As you can see, the image isn't quite loaded correctly. The original:
enter image description here



The code:



import cv2
import imutils
a=imutils.url_to_image("https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png", readFlag=-1)
cv2.imshow("goog", a)
cv2.waitKey()


The implementation of url_to_image in imutils:



def url_to_image(url, readFlag=cv2.IMREAD_COLOR):
# download the image, convert it to a NumPy array, and then read
# it into OpenCV format
resp = urlopen(url)
image = np.asarray(bytearray(resp.read()), dtype="uint8")
image = cv2.imdecode(image, readFlag)

# return the image
return image


I also tried readFlag=cv2.IMREAD_UNCHANGED, but that didn't do the trick either.



please send help










share|improve this question


























    0















    Disaster!
    enter image description here



    As you can see, the image isn't quite loaded correctly. The original:
    enter image description here



    The code:



    import cv2
    import imutils
    a=imutils.url_to_image("https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png", readFlag=-1)
    cv2.imshow("goog", a)
    cv2.waitKey()


    The implementation of url_to_image in imutils:



    def url_to_image(url, readFlag=cv2.IMREAD_COLOR):
    # download the image, convert it to a NumPy array, and then read
    # it into OpenCV format
    resp = urlopen(url)
    image = np.asarray(bytearray(resp.read()), dtype="uint8")
    image = cv2.imdecode(image, readFlag)

    # return the image
    return image


    I also tried readFlag=cv2.IMREAD_UNCHANGED, but that didn't do the trick either.



    please send help










    share|improve this question
























      0












      0








      0








      Disaster!
      enter image description here



      As you can see, the image isn't quite loaded correctly. The original:
      enter image description here



      The code:



      import cv2
      import imutils
      a=imutils.url_to_image("https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png", readFlag=-1)
      cv2.imshow("goog", a)
      cv2.waitKey()


      The implementation of url_to_image in imutils:



      def url_to_image(url, readFlag=cv2.IMREAD_COLOR):
      # download the image, convert it to a NumPy array, and then read
      # it into OpenCV format
      resp = urlopen(url)
      image = np.asarray(bytearray(resp.read()), dtype="uint8")
      image = cv2.imdecode(image, readFlag)

      # return the image
      return image


      I also tried readFlag=cv2.IMREAD_UNCHANGED, but that didn't do the trick either.



      please send help










      share|improve this question














      Disaster!
      enter image description here



      As you can see, the image isn't quite loaded correctly. The original:
      enter image description here



      The code:



      import cv2
      import imutils
      a=imutils.url_to_image("https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png", readFlag=-1)
      cv2.imshow("goog", a)
      cv2.waitKey()


      The implementation of url_to_image in imutils:



      def url_to_image(url, readFlag=cv2.IMREAD_COLOR):
      # download the image, convert it to a NumPy array, and then read
      # it into OpenCV format
      resp = urlopen(url)
      image = np.asarray(bytearray(resp.read()), dtype="uint8")
      image = cv2.imdecode(image, readFlag)

      # return the image
      return image


      I also tried readFlag=cv2.IMREAD_UNCHANGED, but that didn't do the trick either.



      please send help







      python opencv






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 7 at 14:24









      Kelvin WangKelvin Wang

      769




      769






















          2 Answers
          2






          active

          oldest

          votes


















          0














          alright gang we did it



          so I tried another version of displaying:



          plt.figure("Correct")
          plt.imshow(imutils.opencv2matplotlib(a))
          plt.show()


          enter image description here



          No luck it would appear. But then, looking into the opencv2matplotlib source, we find:



          def opencv2matplotlib(image):
          # OpenCV represents images in BGR order; however, Matplotlib
          # expects the image in RGB order, so simply convert from BGR
          # to RGB and return
          return cv2.cvtColor(image, cv2.COLOR_BGR2RGB)


          Aha, but we have 4 channel color (alpha), so by common sense we need cv2.COLOR_BGRA2RGBA not cv2.COLOR_BGR2RGB!!



          Testing this theory:



          plt.figure("Correct")
          plt.imshow(cv2.cvtColor(a, cv2.COLOR_BGRA2RGBA))
          plt.show()


          We get...



          enter image description here



          Whoop dee doop!






          share|improve this answer























          • why don't you use urllib

            – Faizan Khan
            Mar 7 at 14:48











          • I have a solution to this. Do you still need it?

            – Faizan Khan
            Mar 7 at 14:48












          • you won't use matplotlib in that case. rather you'll be using simple imshow(img) to display the image

            – Faizan Khan
            Mar 7 at 14:49











          • ? urllib is used. urlopen is under namespace urllib.request also, cv2.imdecode needs to be called with flag of -1 or it doesn't even write to file correctly

            – Kelvin Wang
            Mar 7 at 15:04



















          0














          # import the necessary packages
          import numpy as np
          import urllib
          import cv2

          def url_to_image(url):
          # download the image, convert it to a NumPy array, and then read
          # it into OpenCV format
          resp = urllib.request.urlopen(url)
          image = np.asarray(bytearray(resp.read()), dtype="uint8")
          image = cv2.imdecode(image, cv2.IMREAD_COLOR)

          # return the image
          return image


          # initialize the list of image URLs to download
          url="http://i.dailymail.co.uk/i/pix/2015/09/01/18/2BE1E88B00000578-3218613-image-m-5_1441127035222.jpg"

          print ("downloading %s" % (url))
          image = url_to_image(url)
          cv2.imshow("Image", image)
          cv2.waitKey(0)


          And the output is:
          the image displayed fetched from the given url






          share|improve this answer























          • This implementation fails on the target url. google.com/images/branding/googlelogo/2x/…

            – Kelvin Wang
            Mar 7 at 15:03












          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55046100%2fimage-loaded-wrong-by-opencv%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          alright gang we did it



          so I tried another version of displaying:



          plt.figure("Correct")
          plt.imshow(imutils.opencv2matplotlib(a))
          plt.show()


          enter image description here



          No luck it would appear. But then, looking into the opencv2matplotlib source, we find:



          def opencv2matplotlib(image):
          # OpenCV represents images in BGR order; however, Matplotlib
          # expects the image in RGB order, so simply convert from BGR
          # to RGB and return
          return cv2.cvtColor(image, cv2.COLOR_BGR2RGB)


          Aha, but we have 4 channel color (alpha), so by common sense we need cv2.COLOR_BGRA2RGBA not cv2.COLOR_BGR2RGB!!



          Testing this theory:



          plt.figure("Correct")
          plt.imshow(cv2.cvtColor(a, cv2.COLOR_BGRA2RGBA))
          plt.show()


          We get...



          enter image description here



          Whoop dee doop!






          share|improve this answer























          • why don't you use urllib

            – Faizan Khan
            Mar 7 at 14:48











          • I have a solution to this. Do you still need it?

            – Faizan Khan
            Mar 7 at 14:48












          • you won't use matplotlib in that case. rather you'll be using simple imshow(img) to display the image

            – Faizan Khan
            Mar 7 at 14:49











          • ? urllib is used. urlopen is under namespace urllib.request also, cv2.imdecode needs to be called with flag of -1 or it doesn't even write to file correctly

            – Kelvin Wang
            Mar 7 at 15:04
















          0














          alright gang we did it



          so I tried another version of displaying:



          plt.figure("Correct")
          plt.imshow(imutils.opencv2matplotlib(a))
          plt.show()


          enter image description here



          No luck it would appear. But then, looking into the opencv2matplotlib source, we find:



          def opencv2matplotlib(image):
          # OpenCV represents images in BGR order; however, Matplotlib
          # expects the image in RGB order, so simply convert from BGR
          # to RGB and return
          return cv2.cvtColor(image, cv2.COLOR_BGR2RGB)


          Aha, but we have 4 channel color (alpha), so by common sense we need cv2.COLOR_BGRA2RGBA not cv2.COLOR_BGR2RGB!!



          Testing this theory:



          plt.figure("Correct")
          plt.imshow(cv2.cvtColor(a, cv2.COLOR_BGRA2RGBA))
          plt.show()


          We get...



          enter image description here



          Whoop dee doop!






          share|improve this answer























          • why don't you use urllib

            – Faizan Khan
            Mar 7 at 14:48











          • I have a solution to this. Do you still need it?

            – Faizan Khan
            Mar 7 at 14:48












          • you won't use matplotlib in that case. rather you'll be using simple imshow(img) to display the image

            – Faizan Khan
            Mar 7 at 14:49











          • ? urllib is used. urlopen is under namespace urllib.request also, cv2.imdecode needs to be called with flag of -1 or it doesn't even write to file correctly

            – Kelvin Wang
            Mar 7 at 15:04














          0












          0








          0







          alright gang we did it



          so I tried another version of displaying:



          plt.figure("Correct")
          plt.imshow(imutils.opencv2matplotlib(a))
          plt.show()


          enter image description here



          No luck it would appear. But then, looking into the opencv2matplotlib source, we find:



          def opencv2matplotlib(image):
          # OpenCV represents images in BGR order; however, Matplotlib
          # expects the image in RGB order, so simply convert from BGR
          # to RGB and return
          return cv2.cvtColor(image, cv2.COLOR_BGR2RGB)


          Aha, but we have 4 channel color (alpha), so by common sense we need cv2.COLOR_BGRA2RGBA not cv2.COLOR_BGR2RGB!!



          Testing this theory:



          plt.figure("Correct")
          plt.imshow(cv2.cvtColor(a, cv2.COLOR_BGRA2RGBA))
          plt.show()


          We get...



          enter image description here



          Whoop dee doop!






          share|improve this answer













          alright gang we did it



          so I tried another version of displaying:



          plt.figure("Correct")
          plt.imshow(imutils.opencv2matplotlib(a))
          plt.show()


          enter image description here



          No luck it would appear. But then, looking into the opencv2matplotlib source, we find:



          def opencv2matplotlib(image):
          # OpenCV represents images in BGR order; however, Matplotlib
          # expects the image in RGB order, so simply convert from BGR
          # to RGB and return
          return cv2.cvtColor(image, cv2.COLOR_BGR2RGB)


          Aha, but we have 4 channel color (alpha), so by common sense we need cv2.COLOR_BGRA2RGBA not cv2.COLOR_BGR2RGB!!



          Testing this theory:



          plt.figure("Correct")
          plt.imshow(cv2.cvtColor(a, cv2.COLOR_BGRA2RGBA))
          plt.show()


          We get...



          enter image description here



          Whoop dee doop!







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 7 at 14:44









          Kelvin WangKelvin Wang

          769




          769












          • why don't you use urllib

            – Faizan Khan
            Mar 7 at 14:48











          • I have a solution to this. Do you still need it?

            – Faizan Khan
            Mar 7 at 14:48












          • you won't use matplotlib in that case. rather you'll be using simple imshow(img) to display the image

            – Faizan Khan
            Mar 7 at 14:49











          • ? urllib is used. urlopen is under namespace urllib.request also, cv2.imdecode needs to be called with flag of -1 or it doesn't even write to file correctly

            – Kelvin Wang
            Mar 7 at 15:04


















          • why don't you use urllib

            – Faizan Khan
            Mar 7 at 14:48











          • I have a solution to this. Do you still need it?

            – Faizan Khan
            Mar 7 at 14:48












          • you won't use matplotlib in that case. rather you'll be using simple imshow(img) to display the image

            – Faizan Khan
            Mar 7 at 14:49











          • ? urllib is used. urlopen is under namespace urllib.request also, cv2.imdecode needs to be called with flag of -1 or it doesn't even write to file correctly

            – Kelvin Wang
            Mar 7 at 15:04

















          why don't you use urllib

          – Faizan Khan
          Mar 7 at 14:48





          why don't you use urllib

          – Faizan Khan
          Mar 7 at 14:48













          I have a solution to this. Do you still need it?

          – Faizan Khan
          Mar 7 at 14:48






          I have a solution to this. Do you still need it?

          – Faizan Khan
          Mar 7 at 14:48














          you won't use matplotlib in that case. rather you'll be using simple imshow(img) to display the image

          – Faizan Khan
          Mar 7 at 14:49





          you won't use matplotlib in that case. rather you'll be using simple imshow(img) to display the image

          – Faizan Khan
          Mar 7 at 14:49













          ? urllib is used. urlopen is under namespace urllib.request also, cv2.imdecode needs to be called with flag of -1 or it doesn't even write to file correctly

          – Kelvin Wang
          Mar 7 at 15:04






          ? urllib is used. urlopen is under namespace urllib.request also, cv2.imdecode needs to be called with flag of -1 or it doesn't even write to file correctly

          – Kelvin Wang
          Mar 7 at 15:04














          0














          # import the necessary packages
          import numpy as np
          import urllib
          import cv2

          def url_to_image(url):
          # download the image, convert it to a NumPy array, and then read
          # it into OpenCV format
          resp = urllib.request.urlopen(url)
          image = np.asarray(bytearray(resp.read()), dtype="uint8")
          image = cv2.imdecode(image, cv2.IMREAD_COLOR)

          # return the image
          return image


          # initialize the list of image URLs to download
          url="http://i.dailymail.co.uk/i/pix/2015/09/01/18/2BE1E88B00000578-3218613-image-m-5_1441127035222.jpg"

          print ("downloading %s" % (url))
          image = url_to_image(url)
          cv2.imshow("Image", image)
          cv2.waitKey(0)


          And the output is:
          the image displayed fetched from the given url






          share|improve this answer























          • This implementation fails on the target url. google.com/images/branding/googlelogo/2x/…

            – Kelvin Wang
            Mar 7 at 15:03
















          0














          # import the necessary packages
          import numpy as np
          import urllib
          import cv2

          def url_to_image(url):
          # download the image, convert it to a NumPy array, and then read
          # it into OpenCV format
          resp = urllib.request.urlopen(url)
          image = np.asarray(bytearray(resp.read()), dtype="uint8")
          image = cv2.imdecode(image, cv2.IMREAD_COLOR)

          # return the image
          return image


          # initialize the list of image URLs to download
          url="http://i.dailymail.co.uk/i/pix/2015/09/01/18/2BE1E88B00000578-3218613-image-m-5_1441127035222.jpg"

          print ("downloading %s" % (url))
          image = url_to_image(url)
          cv2.imshow("Image", image)
          cv2.waitKey(0)


          And the output is:
          the image displayed fetched from the given url






          share|improve this answer























          • This implementation fails on the target url. google.com/images/branding/googlelogo/2x/…

            – Kelvin Wang
            Mar 7 at 15:03














          0












          0








          0







          # import the necessary packages
          import numpy as np
          import urllib
          import cv2

          def url_to_image(url):
          # download the image, convert it to a NumPy array, and then read
          # it into OpenCV format
          resp = urllib.request.urlopen(url)
          image = np.asarray(bytearray(resp.read()), dtype="uint8")
          image = cv2.imdecode(image, cv2.IMREAD_COLOR)

          # return the image
          return image


          # initialize the list of image URLs to download
          url="http://i.dailymail.co.uk/i/pix/2015/09/01/18/2BE1E88B00000578-3218613-image-m-5_1441127035222.jpg"

          print ("downloading %s" % (url))
          image = url_to_image(url)
          cv2.imshow("Image", image)
          cv2.waitKey(0)


          And the output is:
          the image displayed fetched from the given url






          share|improve this answer













          # import the necessary packages
          import numpy as np
          import urllib
          import cv2

          def url_to_image(url):
          # download the image, convert it to a NumPy array, and then read
          # it into OpenCV format
          resp = urllib.request.urlopen(url)
          image = np.asarray(bytearray(resp.read()), dtype="uint8")
          image = cv2.imdecode(image, cv2.IMREAD_COLOR)

          # return the image
          return image


          # initialize the list of image URLs to download
          url="http://i.dailymail.co.uk/i/pix/2015/09/01/18/2BE1E88B00000578-3218613-image-m-5_1441127035222.jpg"

          print ("downloading %s" % (url))
          image = url_to_image(url)
          cv2.imshow("Image", image)
          cv2.waitKey(0)


          And the output is:
          the image displayed fetched from the given url







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 7 at 14:55









          Faizan KhanFaizan Khan

          353312




          353312












          • This implementation fails on the target url. google.com/images/branding/googlelogo/2x/…

            – Kelvin Wang
            Mar 7 at 15:03


















          • This implementation fails on the target url. google.com/images/branding/googlelogo/2x/…

            – Kelvin Wang
            Mar 7 at 15:03

















          This implementation fails on the target url. google.com/images/branding/googlelogo/2x/…

          – Kelvin Wang
          Mar 7 at 15:03






          This implementation fails on the target url. google.com/images/branding/googlelogo/2x/…

          – Kelvin Wang
          Mar 7 at 15:03


















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55046100%2fimage-loaded-wrong-by-opencv%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          1928 у кіно

          Захаров Федір Захарович

          Ель Греко