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

          Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

          Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

          Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved