How to fix error on writing data into a pgm fileHow do I check whether a file exists without exceptions?How do I list all files of a directory?How to read a file line-by-line into a list?How do I write JSON data to a file?Capturing From 2 webcamsopencv error Assertion failed pythonopencv, python and RaspberryPiVideoCapture doesn't seem to work on Debian - opencv 3.2Getting openCV error: Assertion Failed (scn ==3 || scn ==4) in python on RaspberryPi 30 Python-Opencv error: error: (-215) scn == 3 || scn == 4 in function cvtColor

What caused the tendency for conservatives to not support climate change regulations?

The term for the person/group a political party aligns themselves with to appear concerned about the general public

Relativistic resistance transformation

Have powerful mythological heroes ever run away or been deeply afraid?

Can The Malloreon be read without first reading The Belgariad?

Slide Partition from Rowstore to Columnstore

Applicants clearly not having the skills they advertise

Can you use a concentration spell while using Mantle of Majesty?

Are academic associations obliged to comply with the US government?

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

How to properly maintain eye contact with people that have distinctive facial features?

Beginner's snake game using PyGame

If a massive object like Jupiter flew past the Earth how close would it need to come to pull people off of the surface?

How much current can Baofeng UV-5R provide on +V pin?

Is there a way to save this session?

Why would Lupin kill Pettigrew?

The most awesome army: 80 men left and 81 returned. Is it true?

Alleged sexist comments charges presented toward me

Select row of data if next row contains zero

How can I offer a test ride while selling a bike?

Rotated Position of Integers

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

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

Creating Fictional Slavic Place Names



How to fix error on writing data into a pgm file


How do I check whether a file exists without exceptions?How do I list all files of a directory?How to read a file line-by-line into a list?How do I write JSON data to a file?Capturing From 2 webcamsopencv error Assertion failed pythonopencv, python and RaspberryPiVideoCapture doesn't seem to work on Debian - opencv 3.2Getting openCV error: Assertion Failed (scn ==3 || scn ==4) in python on RaspberryPi 30 Python-Opencv error: error: (-215) scn == 3 || scn == 4 in function cvtColor






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








0















How to fix error when try to convert frame into grayscale?



Error message: cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) cv2.error: OpenCV(4.0.0) c:projectsopencv-pythonopencvmodulesimgprocsrccolor.hpp:259: error: (-2:Unspecified error) in function '__cdecl cv::CvtHelper,struct cv::Set<1,-1,-1>,struct cv::Set<0,2,5>,2>::CvtHelper(const class cv::_InputArray &,const class cv::_OutputArray &,int)' > Invalid number of channels in input image: > 'VScn::contains(scn)' > where > 'scn' is 1



class OpenCVCapture(object):
def __init__(self, device_id=0):
"""Create an OpenCV capture object associated with the provided webcam
device ID.
"""
# Open the camera.
self._camera = cv2.VideoCapture(device_id)
if not self._camera.isOpened():
self._camera.open()
# Start a thread to continuously capture frames.
# This must be done because different layers of buffering in the webcam
# and OS drivers will cause you to retrieve old frames if they aren't
# continuously read.
self._capture_frame = None
# Use a lock to prevent access concurrent access to the camera.
self._capture_lock = threading.Lock()
self._capture_thread = threading.Thread(target=self._grab_frames)
self._capture_thread.daemon = True
self._capture_thread.start()

def _grab_frames(self):
while True:
retval, frame = self._camera.read()
frame = cv2.cvtColor(frame, cv2.COLOR_RGB2GRAY)
with self._capture_lock:
self._capture_frame = None
if retval:
self._capture_frame = frame
time.sleep(1.0/CAPTURE_HZ)

def read(self):
"""Read a single frame from the camera and return the data as an OpenCV
image (which is a numpy array).
"""
frame = None
with self._capture_lock:
frame = self._capture_frame

# If there are problems, keep retrying until an image can be read.
while frame is None:
time.sleep(0)
with self._capture_lock:
frame = self._capture_frame
# Save captured image for debugging.
cv2.imwrite(config.DEBUG_IMAGE, frame)
# Return the capture image data.
return frame









share|improve this question
























  • Please, provide frame.shape and frame.dtype

    – Berriel
    Mar 24 at 11:15











  • You might want to proof-read your post (especially title) -- imwrite (as the name would suggest) isn't used for reading... | Also add a proper minimal reproducible example -- right now you claim you "feed in grayscale image"... but how do we know that's actually the case?

    – Dan Mašek
    Mar 24 at 11:19












  • @DanMašek i added in code which i turn the image frame into grayscale, thanks for the correction

    – Nicholas Chuah
    Mar 24 at 11:34











  • @Berriel the shape is (480, 640, 3) and dtype uint8

    – Nicholas Chuah
    Mar 24 at 11:39











  • Given that the 3rd value of shape (the number of channels) is 3, it's definitely not a grayscale image at that point... which seems rather odd given that code.

    – Dan Mašek
    Mar 24 at 11:42


















0















How to fix error when try to convert frame into grayscale?



Error message: cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) cv2.error: OpenCV(4.0.0) c:projectsopencv-pythonopencvmodulesimgprocsrccolor.hpp:259: error: (-2:Unspecified error) in function '__cdecl cv::CvtHelper,struct cv::Set<1,-1,-1>,struct cv::Set<0,2,5>,2>::CvtHelper(const class cv::_InputArray &,const class cv::_OutputArray &,int)' > Invalid number of channels in input image: > 'VScn::contains(scn)' > where > 'scn' is 1



class OpenCVCapture(object):
def __init__(self, device_id=0):
"""Create an OpenCV capture object associated with the provided webcam
device ID.
"""
# Open the camera.
self._camera = cv2.VideoCapture(device_id)
if not self._camera.isOpened():
self._camera.open()
# Start a thread to continuously capture frames.
# This must be done because different layers of buffering in the webcam
# and OS drivers will cause you to retrieve old frames if they aren't
# continuously read.
self._capture_frame = None
# Use a lock to prevent access concurrent access to the camera.
self._capture_lock = threading.Lock()
self._capture_thread = threading.Thread(target=self._grab_frames)
self._capture_thread.daemon = True
self._capture_thread.start()

def _grab_frames(self):
while True:
retval, frame = self._camera.read()
frame = cv2.cvtColor(frame, cv2.COLOR_RGB2GRAY)
with self._capture_lock:
self._capture_frame = None
if retval:
self._capture_frame = frame
time.sleep(1.0/CAPTURE_HZ)

def read(self):
"""Read a single frame from the camera and return the data as an OpenCV
image (which is a numpy array).
"""
frame = None
with self._capture_lock:
frame = self._capture_frame

# If there are problems, keep retrying until an image can be read.
while frame is None:
time.sleep(0)
with self._capture_lock:
frame = self._capture_frame
# Save captured image for debugging.
cv2.imwrite(config.DEBUG_IMAGE, frame)
# Return the capture image data.
return frame









share|improve this question
























  • Please, provide frame.shape and frame.dtype

    – Berriel
    Mar 24 at 11:15











  • You might want to proof-read your post (especially title) -- imwrite (as the name would suggest) isn't used for reading... | Also add a proper minimal reproducible example -- right now you claim you "feed in grayscale image"... but how do we know that's actually the case?

    – Dan Mašek
    Mar 24 at 11:19












  • @DanMašek i added in code which i turn the image frame into grayscale, thanks for the correction

    – Nicholas Chuah
    Mar 24 at 11:34











  • @Berriel the shape is (480, 640, 3) and dtype uint8

    – Nicholas Chuah
    Mar 24 at 11:39











  • Given that the 3rd value of shape (the number of channels) is 3, it's definitely not a grayscale image at that point... which seems rather odd given that code.

    – Dan Mašek
    Mar 24 at 11:42














0












0








0








How to fix error when try to convert frame into grayscale?



Error message: cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) cv2.error: OpenCV(4.0.0) c:projectsopencv-pythonopencvmodulesimgprocsrccolor.hpp:259: error: (-2:Unspecified error) in function '__cdecl cv::CvtHelper,struct cv::Set<1,-1,-1>,struct cv::Set<0,2,5>,2>::CvtHelper(const class cv::_InputArray &,const class cv::_OutputArray &,int)' > Invalid number of channels in input image: > 'VScn::contains(scn)' > where > 'scn' is 1



class OpenCVCapture(object):
def __init__(self, device_id=0):
"""Create an OpenCV capture object associated with the provided webcam
device ID.
"""
# Open the camera.
self._camera = cv2.VideoCapture(device_id)
if not self._camera.isOpened():
self._camera.open()
# Start a thread to continuously capture frames.
# This must be done because different layers of buffering in the webcam
# and OS drivers will cause you to retrieve old frames if they aren't
# continuously read.
self._capture_frame = None
# Use a lock to prevent access concurrent access to the camera.
self._capture_lock = threading.Lock()
self._capture_thread = threading.Thread(target=self._grab_frames)
self._capture_thread.daemon = True
self._capture_thread.start()

def _grab_frames(self):
while True:
retval, frame = self._camera.read()
frame = cv2.cvtColor(frame, cv2.COLOR_RGB2GRAY)
with self._capture_lock:
self._capture_frame = None
if retval:
self._capture_frame = frame
time.sleep(1.0/CAPTURE_HZ)

def read(self):
"""Read a single frame from the camera and return the data as an OpenCV
image (which is a numpy array).
"""
frame = None
with self._capture_lock:
frame = self._capture_frame

# If there are problems, keep retrying until an image can be read.
while frame is None:
time.sleep(0)
with self._capture_lock:
frame = self._capture_frame
# Save captured image for debugging.
cv2.imwrite(config.DEBUG_IMAGE, frame)
# Return the capture image data.
return frame









share|improve this question
















How to fix error when try to convert frame into grayscale?



Error message: cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) cv2.error: OpenCV(4.0.0) c:projectsopencv-pythonopencvmodulesimgprocsrccolor.hpp:259: error: (-2:Unspecified error) in function '__cdecl cv::CvtHelper,struct cv::Set<1,-1,-1>,struct cv::Set<0,2,5>,2>::CvtHelper(const class cv::_InputArray &,const class cv::_OutputArray &,int)' > Invalid number of channels in input image: > 'VScn::contains(scn)' > where > 'scn' is 1



class OpenCVCapture(object):
def __init__(self, device_id=0):
"""Create an OpenCV capture object associated with the provided webcam
device ID.
"""
# Open the camera.
self._camera = cv2.VideoCapture(device_id)
if not self._camera.isOpened():
self._camera.open()
# Start a thread to continuously capture frames.
# This must be done because different layers of buffering in the webcam
# and OS drivers will cause you to retrieve old frames if they aren't
# continuously read.
self._capture_frame = None
# Use a lock to prevent access concurrent access to the camera.
self._capture_lock = threading.Lock()
self._capture_thread = threading.Thread(target=self._grab_frames)
self._capture_thread.daemon = True
self._capture_thread.start()

def _grab_frames(self):
while True:
retval, frame = self._camera.read()
frame = cv2.cvtColor(frame, cv2.COLOR_RGB2GRAY)
with self._capture_lock:
self._capture_frame = None
if retval:
self._capture_frame = frame
time.sleep(1.0/CAPTURE_HZ)

def read(self):
"""Read a single frame from the camera and return the data as an OpenCV
image (which is a numpy array).
"""
frame = None
with self._capture_lock:
frame = self._capture_frame

# If there are problems, keep retrying until an image can be read.
while frame is None:
time.sleep(0)
with self._capture_lock:
frame = self._capture_frame
# Save captured image for debugging.
cv2.imwrite(config.DEBUG_IMAGE, frame)
# Return the capture image data.
return frame






python python-3.x opencv cv2 opencv4






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 24 at 12:03







Nicholas Chuah

















asked Mar 24 at 11:13









Nicholas ChuahNicholas Chuah

45




45












  • Please, provide frame.shape and frame.dtype

    – Berriel
    Mar 24 at 11:15











  • You might want to proof-read your post (especially title) -- imwrite (as the name would suggest) isn't used for reading... | Also add a proper minimal reproducible example -- right now you claim you "feed in grayscale image"... but how do we know that's actually the case?

    – Dan Mašek
    Mar 24 at 11:19












  • @DanMašek i added in code which i turn the image frame into grayscale, thanks for the correction

    – Nicholas Chuah
    Mar 24 at 11:34











  • @Berriel the shape is (480, 640, 3) and dtype uint8

    – Nicholas Chuah
    Mar 24 at 11:39











  • Given that the 3rd value of shape (the number of channels) is 3, it's definitely not a grayscale image at that point... which seems rather odd given that code.

    – Dan Mašek
    Mar 24 at 11:42


















  • Please, provide frame.shape and frame.dtype

    – Berriel
    Mar 24 at 11:15











  • You might want to proof-read your post (especially title) -- imwrite (as the name would suggest) isn't used for reading... | Also add a proper minimal reproducible example -- right now you claim you "feed in grayscale image"... but how do we know that's actually the case?

    – Dan Mašek
    Mar 24 at 11:19












  • @DanMašek i added in code which i turn the image frame into grayscale, thanks for the correction

    – Nicholas Chuah
    Mar 24 at 11:34











  • @Berriel the shape is (480, 640, 3) and dtype uint8

    – Nicholas Chuah
    Mar 24 at 11:39











  • Given that the 3rd value of shape (the number of channels) is 3, it's definitely not a grayscale image at that point... which seems rather odd given that code.

    – Dan Mašek
    Mar 24 at 11:42

















Please, provide frame.shape and frame.dtype

– Berriel
Mar 24 at 11:15





Please, provide frame.shape and frame.dtype

– Berriel
Mar 24 at 11:15













You might want to proof-read your post (especially title) -- imwrite (as the name would suggest) isn't used for reading... | Also add a proper minimal reproducible example -- right now you claim you "feed in grayscale image"... but how do we know that's actually the case?

– Dan Mašek
Mar 24 at 11:19






You might want to proof-read your post (especially title) -- imwrite (as the name would suggest) isn't used for reading... | Also add a proper minimal reproducible example -- right now you claim you "feed in grayscale image"... but how do we know that's actually the case?

– Dan Mašek
Mar 24 at 11:19














@DanMašek i added in code which i turn the image frame into grayscale, thanks for the correction

– Nicholas Chuah
Mar 24 at 11:34





@DanMašek i added in code which i turn the image frame into grayscale, thanks for the correction

– Nicholas Chuah
Mar 24 at 11:34













@Berriel the shape is (480, 640, 3) and dtype uint8

– Nicholas Chuah
Mar 24 at 11:39





@Berriel the shape is (480, 640, 3) and dtype uint8

– Nicholas Chuah
Mar 24 at 11:39













Given that the 3rd value of shape (the number of channels) is 3, it's definitely not a grayscale image at that point... which seems rather odd given that code.

– Dan Mašek
Mar 24 at 11:42






Given that the 3rd value of shape (the number of channels) is 3, it's definitely not a grayscale image at that point... which seems rather odd given that code.

– Dan Mašek
Mar 24 at 11:42













0






active

oldest

votes












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%2f55323206%2fhow-to-fix-error-on-writing-data-into-a-pgm-file%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















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%2f55323206%2fhow-to-fix-error-on-writing-data-into-a-pgm-file%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

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

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

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현