How do I convert openCV transformed images into its orignal formatConvert OpenCv DCT to AndroidCapturing From 2 webcamsOpenCV Assertion Failed error: (-215) scn == 3 || scn == 4 in function cv::cvtColor works ALTERNATE timesTrying to manipulate the saturation on a image on OpenCVraspberry pi camera motion detectionopencv, python and RaspberryPiHarr Cascade CV2 error: (-215) scn == 3 || scn == 4 in function cv::ipp_cvtColorHow to convert a single BGR array to HSV array in Python with OpenCV?Differences between CV2 image processing and tf.image processingText Recognition with Python using tesserocr library

Cross Correlation, how can any signals except the trivial cases be uncorrelated?

Homophone fills the blanks

Concise way to draw this pyramid

Setting extra bits in a bool makes it true and false at the same time

Unconventional Opposites

Is there a term for this?

Hygienic footwear for prehensile feet?

Is it possible to kill all life on Earth?

Sucuri detects malware on wordpress but I can't find the malicious code

How should I push back against my job assigning "homework"?

Working in the USA for living expenses only; allowed on VWP?

Can The Malloreon be read without first reading The Belgariad?

What is the best option to connect old computer to modern TV

Are there practical reasons to NOT use a stepper motor with lead screw for the X and or Y axes?

Is there a way to save this session?

How is it possible for Mordenkainen to be alive during the Curse of Strahd adventure?

What is the correct expression of 10/20, 20/30, 30/40 etc?

Is this cancel button needed?

California: "For quality assurance, this phone call is being recorded"

Can you please explain this joke: "I'm going bananas is what I tell my bananas before I leave the house"?

What people are called boars ("кабан") and why?

Filling region bounded by multiple paths

Self referencing scalar function nesting level exceeded when adding a select

Is there any Biblical Basis for 400 years of silence between Old and New Testament?



How do I convert openCV transformed images into its orignal format


Convert OpenCv DCT to AndroidCapturing From 2 webcamsOpenCV Assertion Failed error: (-215) scn == 3 || scn == 4 in function cv::cvtColor works ALTERNATE timesTrying to manipulate the saturation on a image on OpenCVraspberry pi camera motion detectionopencv, python and RaspberryPiHarr Cascade CV2 error: (-215) scn == 3 || scn == 4 in function cv::ipp_cvtColorHow to convert a single BGR array to HSV array in Python with OpenCV?Differences between CV2 image processing and tf.image processingText Recognition with Python using tesserocr library






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I have resized my orignal image from 200x200 to 128x128 , since opencv in default read in BGR , I took care of that but after resizing it becomes grayscale(as expected) but I can't convert back to its RGB format



orignal = cv2.imread(os.path.join("/path","some_image.png"),0)

rgb = cv2.cvtColor(orignal, cv2.COLOR_BGR2RGB)

resized = cv2.resize(rgb,(128,128))

backtorgb = cv2.cvtColor(resized,cv2.COLOR_GRAY2RGB)

plt.imshow(backtorgb)


here last line gives error:




error: OpenCV(4.0.0) /io/opencv/modules/imgproc/src/color.hpp:259: error: (-2:Unspecified error) in function 'cv::CvtHelper::CvtHelper(cv::InputArray, cv::OutputArray, int) [with VScn = cv::Set<1>; VDcn = cv::Set<3, 4>; VDepth = cv::Set<0, 2, 5>; cv::SizePolicy sizePolicy = (cv::SizePolicy)2u; cv::InputArray = const cv::_InputArray&; cv::OutputArray = const cv::_OutputArray&]'
Invalid number of channels in input image:
'VScn::contains(scn)'
where
'scn' is 3











share|improve this question

















  • 1





    "after resizing it becomes grayscale(as expected)" -- huh? I certainly wouldn't expect resizing to make a color image grayscale. The error message confirms it's still 3-channel.

    – Dan Mašek
    Mar 24 at 12:11


















0















I have resized my orignal image from 200x200 to 128x128 , since opencv in default read in BGR , I took care of that but after resizing it becomes grayscale(as expected) but I can't convert back to its RGB format



orignal = cv2.imread(os.path.join("/path","some_image.png"),0)

rgb = cv2.cvtColor(orignal, cv2.COLOR_BGR2RGB)

resized = cv2.resize(rgb,(128,128))

backtorgb = cv2.cvtColor(resized,cv2.COLOR_GRAY2RGB)

plt.imshow(backtorgb)


here last line gives error:




error: OpenCV(4.0.0) /io/opencv/modules/imgproc/src/color.hpp:259: error: (-2:Unspecified error) in function 'cv::CvtHelper::CvtHelper(cv::InputArray, cv::OutputArray, int) [with VScn = cv::Set<1>; VDcn = cv::Set<3, 4>; VDepth = cv::Set<0, 2, 5>; cv::SizePolicy sizePolicy = (cv::SizePolicy)2u; cv::InputArray = const cv::_InputArray&; cv::OutputArray = const cv::_OutputArray&]'
Invalid number of channels in input image:
'VScn::contains(scn)'
where
'scn' is 3











share|improve this question

















  • 1





    "after resizing it becomes grayscale(as expected)" -- huh? I certainly wouldn't expect resizing to make a color image grayscale. The error message confirms it's still 3-channel.

    – Dan Mašek
    Mar 24 at 12:11














0












0








0








I have resized my orignal image from 200x200 to 128x128 , since opencv in default read in BGR , I took care of that but after resizing it becomes grayscale(as expected) but I can't convert back to its RGB format



orignal = cv2.imread(os.path.join("/path","some_image.png"),0)

rgb = cv2.cvtColor(orignal, cv2.COLOR_BGR2RGB)

resized = cv2.resize(rgb,(128,128))

backtorgb = cv2.cvtColor(resized,cv2.COLOR_GRAY2RGB)

plt.imshow(backtorgb)


here last line gives error:




error: OpenCV(4.0.0) /io/opencv/modules/imgproc/src/color.hpp:259: error: (-2:Unspecified error) in function 'cv::CvtHelper::CvtHelper(cv::InputArray, cv::OutputArray, int) [with VScn = cv::Set<1>; VDcn = cv::Set<3, 4>; VDepth = cv::Set<0, 2, 5>; cv::SizePolicy sizePolicy = (cv::SizePolicy)2u; cv::InputArray = const cv::_InputArray&; cv::OutputArray = const cv::_OutputArray&]'
Invalid number of channels in input image:
'VScn::contains(scn)'
where
'scn' is 3











share|improve this question














I have resized my orignal image from 200x200 to 128x128 , since opencv in default read in BGR , I took care of that but after resizing it becomes grayscale(as expected) but I can't convert back to its RGB format



orignal = cv2.imread(os.path.join("/path","some_image.png"),0)

rgb = cv2.cvtColor(orignal, cv2.COLOR_BGR2RGB)

resized = cv2.resize(rgb,(128,128))

backtorgb = cv2.cvtColor(resized,cv2.COLOR_GRAY2RGB)

plt.imshow(backtorgb)


here last line gives error:




error: OpenCV(4.0.0) /io/opencv/modules/imgproc/src/color.hpp:259: error: (-2:Unspecified error) in function 'cv::CvtHelper::CvtHelper(cv::InputArray, cv::OutputArray, int) [with VScn = cv::Set<1>; VDcn = cv::Set<3, 4>; VDepth = cv::Set<0, 2, 5>; cv::SizePolicy sizePolicy = (cv::SizePolicy)2u; cv::InputArray = const cv::_InputArray&; cv::OutputArray = const cv::_OutputArray&]'
Invalid number of channels in input image:
'VScn::contains(scn)'
where
'scn' is 3








python opencv






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 24 at 11:48









SaurabhSaurabh

280313




280313







  • 1





    "after resizing it becomes grayscale(as expected)" -- huh? I certainly wouldn't expect resizing to make a color image grayscale. The error message confirms it's still 3-channel.

    – Dan Mašek
    Mar 24 at 12:11













  • 1





    "after resizing it becomes grayscale(as expected)" -- huh? I certainly wouldn't expect resizing to make a color image grayscale. The error message confirms it's still 3-channel.

    – Dan Mašek
    Mar 24 at 12:11








1




1





"after resizing it becomes grayscale(as expected)" -- huh? I certainly wouldn't expect resizing to make a color image grayscale. The error message confirms it's still 3-channel.

– Dan Mašek
Mar 24 at 12:11






"after resizing it becomes grayscale(as expected)" -- huh? I certainly wouldn't expect resizing to make a color image grayscale. The error message confirms it's still 3-channel.

– Dan Mašek
Mar 24 at 12:11













2 Answers
2






active

oldest

votes


















2














Resizing an image using cv2.resize() should not turn a colored image into grayscale. It simply resizes the image src down to or up to the specified size. To convert an image to grayscale, use cv2.cvtColor(src, cv2.COLOR_BGR2GRAY). Your error message also confirms that the resized image has 3 color channels. Here is confirmation that cv2.resize() does not change an image into grayscale.



example



import cv2

image_file = 'assets/color_palette.jpg'

original = cv2.imread(image_file)
cv2.imshow('original', original)

rgb = cv2.cvtColor(original, cv2.COLOR_BGR2RGB)
cv2.imshow('rgb', rgb)

resized = cv2.resize(rgb, (128,128))
cv2.imshow('resized', resized)

key = cv2.waitKey(0)





share|improve this answer






























    0














    You could try something like this for the resize option:



    It's important to keep in mind aspect ratio so the image doesn't look skewed or distorted -- so we need calculate the ratio of the new image to the old image



    image = cv2.imread(os.path.join("/path","some_image.png"),0) 
    Ratio = 100.0 / image.shape[1]
    dimensions = (128, int(image.shape[0] * Ratio))

    # perform the actual resizing of the image and show it
    resized = cv2.resize(image, dimensions , interpolation = cv2.INTER_AREA)
    cv2.imshow("resized", resized)
    cv2.waitKey(0)


    What's happening in the resize :



    The first parameter is the original image that we want to resize. The second argument is the calculated dimensions for the new image that we calculated earlier in the dimensions variable. The third parameter then just tells us which algorithm to use.



    If you need to convert the image from BGR to RGB you should be able to do that just after resizing. You should be able to just resize it before converting it






    share|improve this answer























    • Not sure how aspect ratio is relevant here or how this addresses the question. The only problem I see is OP's odd (and incorrect) expectation that resizing will change the colour space/channel count.

      – Dan Mašek
      Mar 24 at 12:24











    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%2f55323468%2fhow-do-i-convert-opencv-transformed-images-into-its-orignal-format%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









    2














    Resizing an image using cv2.resize() should not turn a colored image into grayscale. It simply resizes the image src down to or up to the specified size. To convert an image to grayscale, use cv2.cvtColor(src, cv2.COLOR_BGR2GRAY). Your error message also confirms that the resized image has 3 color channels. Here is confirmation that cv2.resize() does not change an image into grayscale.



    example



    import cv2

    image_file = 'assets/color_palette.jpg'

    original = cv2.imread(image_file)
    cv2.imshow('original', original)

    rgb = cv2.cvtColor(original, cv2.COLOR_BGR2RGB)
    cv2.imshow('rgb', rgb)

    resized = cv2.resize(rgb, (128,128))
    cv2.imshow('resized', resized)

    key = cv2.waitKey(0)





    share|improve this answer



























      2














      Resizing an image using cv2.resize() should not turn a colored image into grayscale. It simply resizes the image src down to or up to the specified size. To convert an image to grayscale, use cv2.cvtColor(src, cv2.COLOR_BGR2GRAY). Your error message also confirms that the resized image has 3 color channels. Here is confirmation that cv2.resize() does not change an image into grayscale.



      example



      import cv2

      image_file = 'assets/color_palette.jpg'

      original = cv2.imread(image_file)
      cv2.imshow('original', original)

      rgb = cv2.cvtColor(original, cv2.COLOR_BGR2RGB)
      cv2.imshow('rgb', rgb)

      resized = cv2.resize(rgb, (128,128))
      cv2.imshow('resized', resized)

      key = cv2.waitKey(0)





      share|improve this answer

























        2












        2








        2







        Resizing an image using cv2.resize() should not turn a colored image into grayscale. It simply resizes the image src down to or up to the specified size. To convert an image to grayscale, use cv2.cvtColor(src, cv2.COLOR_BGR2GRAY). Your error message also confirms that the resized image has 3 color channels. Here is confirmation that cv2.resize() does not change an image into grayscale.



        example



        import cv2

        image_file = 'assets/color_palette.jpg'

        original = cv2.imread(image_file)
        cv2.imshow('original', original)

        rgb = cv2.cvtColor(original, cv2.COLOR_BGR2RGB)
        cv2.imshow('rgb', rgb)

        resized = cv2.resize(rgb, (128,128))
        cv2.imshow('resized', resized)

        key = cv2.waitKey(0)





        share|improve this answer













        Resizing an image using cv2.resize() should not turn a colored image into grayscale. It simply resizes the image src down to or up to the specified size. To convert an image to grayscale, use cv2.cvtColor(src, cv2.COLOR_BGR2GRAY). Your error message also confirms that the resized image has 3 color channels. Here is confirmation that cv2.resize() does not change an image into grayscale.



        example



        import cv2

        image_file = 'assets/color_palette.jpg'

        original = cv2.imread(image_file)
        cv2.imshow('original', original)

        rgb = cv2.cvtColor(original, cv2.COLOR_BGR2RGB)
        cv2.imshow('rgb', rgb)

        resized = cv2.resize(rgb, (128,128))
        cv2.imshow('resized', resized)

        key = cv2.waitKey(0)






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 25 at 22:44









        nathancynathancy

        2,4041624




        2,4041624























            0














            You could try something like this for the resize option:



            It's important to keep in mind aspect ratio so the image doesn't look skewed or distorted -- so we need calculate the ratio of the new image to the old image



            image = cv2.imread(os.path.join("/path","some_image.png"),0) 
            Ratio = 100.0 / image.shape[1]
            dimensions = (128, int(image.shape[0] * Ratio))

            # perform the actual resizing of the image and show it
            resized = cv2.resize(image, dimensions , interpolation = cv2.INTER_AREA)
            cv2.imshow("resized", resized)
            cv2.waitKey(0)


            What's happening in the resize :



            The first parameter is the original image that we want to resize. The second argument is the calculated dimensions for the new image that we calculated earlier in the dimensions variable. The third parameter then just tells us which algorithm to use.



            If you need to convert the image from BGR to RGB you should be able to do that just after resizing. You should be able to just resize it before converting it






            share|improve this answer























            • Not sure how aspect ratio is relevant here or how this addresses the question. The only problem I see is OP's odd (and incorrect) expectation that resizing will change the colour space/channel count.

              – Dan Mašek
              Mar 24 at 12:24















            0














            You could try something like this for the resize option:



            It's important to keep in mind aspect ratio so the image doesn't look skewed or distorted -- so we need calculate the ratio of the new image to the old image



            image = cv2.imread(os.path.join("/path","some_image.png"),0) 
            Ratio = 100.0 / image.shape[1]
            dimensions = (128, int(image.shape[0] * Ratio))

            # perform the actual resizing of the image and show it
            resized = cv2.resize(image, dimensions , interpolation = cv2.INTER_AREA)
            cv2.imshow("resized", resized)
            cv2.waitKey(0)


            What's happening in the resize :



            The first parameter is the original image that we want to resize. The second argument is the calculated dimensions for the new image that we calculated earlier in the dimensions variable. The third parameter then just tells us which algorithm to use.



            If you need to convert the image from BGR to RGB you should be able to do that just after resizing. You should be able to just resize it before converting it






            share|improve this answer























            • Not sure how aspect ratio is relevant here or how this addresses the question. The only problem I see is OP's odd (and incorrect) expectation that resizing will change the colour space/channel count.

              – Dan Mašek
              Mar 24 at 12:24













            0












            0








            0







            You could try something like this for the resize option:



            It's important to keep in mind aspect ratio so the image doesn't look skewed or distorted -- so we need calculate the ratio of the new image to the old image



            image = cv2.imread(os.path.join("/path","some_image.png"),0) 
            Ratio = 100.0 / image.shape[1]
            dimensions = (128, int(image.shape[0] * Ratio))

            # perform the actual resizing of the image and show it
            resized = cv2.resize(image, dimensions , interpolation = cv2.INTER_AREA)
            cv2.imshow("resized", resized)
            cv2.waitKey(0)


            What's happening in the resize :



            The first parameter is the original image that we want to resize. The second argument is the calculated dimensions for the new image that we calculated earlier in the dimensions variable. The third parameter then just tells us which algorithm to use.



            If you need to convert the image from BGR to RGB you should be able to do that just after resizing. You should be able to just resize it before converting it






            share|improve this answer













            You could try something like this for the resize option:



            It's important to keep in mind aspect ratio so the image doesn't look skewed or distorted -- so we need calculate the ratio of the new image to the old image



            image = cv2.imread(os.path.join("/path","some_image.png"),0) 
            Ratio = 100.0 / image.shape[1]
            dimensions = (128, int(image.shape[0] * Ratio))

            # perform the actual resizing of the image and show it
            resized = cv2.resize(image, dimensions , interpolation = cv2.INTER_AREA)
            cv2.imshow("resized", resized)
            cv2.waitKey(0)


            What's happening in the resize :



            The first parameter is the original image that we want to resize. The second argument is the calculated dimensions for the new image that we calculated earlier in the dimensions variable. The third parameter then just tells us which algorithm to use.



            If you need to convert the image from BGR to RGB you should be able to do that just after resizing. You should be able to just resize it before converting it







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 24 at 12:11









            Neil HoustonNeil Houston

            40110




            40110












            • Not sure how aspect ratio is relevant here or how this addresses the question. The only problem I see is OP's odd (and incorrect) expectation that resizing will change the colour space/channel count.

              – Dan Mašek
              Mar 24 at 12:24

















            • Not sure how aspect ratio is relevant here or how this addresses the question. The only problem I see is OP's odd (and incorrect) expectation that resizing will change the colour space/channel count.

              – Dan Mašek
              Mar 24 at 12:24
















            Not sure how aspect ratio is relevant here or how this addresses the question. The only problem I see is OP's odd (and incorrect) expectation that resizing will change the colour space/channel count.

            – Dan Mašek
            Mar 24 at 12:24





            Not sure how aspect ratio is relevant here or how this addresses the question. The only problem I see is OP's odd (and incorrect) expectation that resizing will change the colour space/channel count.

            – Dan Mašek
            Mar 24 at 12:24

















            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%2f55323468%2fhow-do-i-convert-opencv-transformed-images-into-its-orignal-format%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

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

            155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해