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;
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
add a comment |
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
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
add a comment |
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
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
python opencv
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
add a comment |
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
add a comment |
2 Answers
2
active
oldest
votes
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.

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)
add a comment |
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
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.

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)
add a comment |
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.

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)
add a comment |
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.

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)
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.

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)
answered Mar 25 at 22:44
nathancynathancy
2,4041624
2,4041624
add a comment |
add a comment |
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
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
add a comment |
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
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
add a comment |
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
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
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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