Giter Club home page Giter Club logo

Comments (3)

Kumataro avatar Kumataro commented on June 5, 2024 1

Hello, I'm sorry but if you want to ask question, https://forum.opencv.org/ is better.
But because you said an exception that is not cv::Exception occurred, I comment it.


As the necessary information has not been shared sufficiently at this time, we are unable to investigate the cause.
So I believe only you can investigate it .

As first, please could you split investigation in to 2 steps ?

  • Step1 ) Determine which is this problem in commonly part or Jpeg part.
  • Step2 ) (If jpeg part) Determine where line make exception.

Step1 ) Determine which is this problem in commonly part or Jpeg part.

"can't write data..." message is output from here. This is commonly part.

catch (const cv::Exception& e)
{
CV_LOG_ERROR(NULL, "imwrite_('" << filename << "'): can't write data: " << e.what());
}
catch (...)
{
CV_LOG_ERROR(NULL, "imwrite_('" << filename << "'): can't write data: unknown exception");
}

This is commonly part. Could you try with BMP encoder?

-	imwrite("1.jpg", t_frame[index]);
+	imwrite("1.bmp", t_frame[index]);

Step2 ) (If jpeg part) Determine where line make exception.

If this problem occurs with only "1.jpg", not "1.bmp". Please could you try to isolate the cause ?
JpegEncoder is very simple.

Or please could you share more information, like before and after log, Mat information ?
(It is difficult to investigate without reproducible data.)

https://github.com/opencv/opencv/blob/4.9.0/modules/imgcodecs/src/grfmt_jpeg.cpp#L580

Appendix

There are different between source code and comment, so maybe it is hard to determine which is input Mat valid or invalid.

	//* These judgements don't work.
	if (t_frame[index].empty() || t_frame[index].dims <= 0 || t_frame[index].channels() <= 0) {
		std::cout << "Mat is invalid." << t_frame[index].cols << ",h:" << t_frame[index].rows << std::endl;
	}
	else {
		//* isContinuous: true type:16
		std::cout << "Mat is valid,w:" << t_frame[index].cols << ",h:" << t_frame[index].rows << std::endl;
		std::cout << "Mat isContinuous:" << t_frame[index].isContinuous() << ";type:" << t_frame[index].type() << std::endl;
	}

For Jpeg Encoder...

  • t_frame[index].empty() is needed.
  • t_frame[index].dims <= 0 should be t_frame[index].dims == 2. But usually it is not needed.
  • t_frame[index].channels() <= 0 should be check 1 or 3.
  • 1920x1080 is OK, but it is not checked.
  • isContinuous is not important because JpegEncoder handle each lines.
  • type:16 ( CV_8UC3 ) is OK, but it is not checked, only comment.

from opencv.

JianJingGao avatar JianJingGao commented on June 5, 2024

Hello, I'm sorry but if you want to ask question, https://forum.opencv.org/ is better. But because you said an exception that is not cv::Exception occurred, I comment it.

As the necessary information has not been shared sufficiently at this time, we are unable to investigate the cause. So I believe only you can investigate it .

As first, please could you split investigation in to 2 steps ?

  • Step1 ) Determine which is this problem in commonly part or Jpeg part.
  • Step2 ) (If jpeg part) Determine where line make exception.

Step1 ) Determine which is this problem in commonly part or Jpeg part.

"can't write data..." message is output from here. This is commonly part.

catch (const cv::Exception& e)
{
CV_LOG_ERROR(NULL, "imwrite_('" << filename << "'): can't write data: " << e.what());
}
catch (...)
{
CV_LOG_ERROR(NULL, "imwrite_('" << filename << "'): can't write data: unknown exception");
}

This is commonly part. Could you try with BMP encoder?

-	imwrite("1.jpg", t_frame[index]);
+	imwrite("1.bmp", t_frame[index]);

Step2 ) (If jpeg part) Determine where line make exception.

If this problem occurs with only "1.jpg", not "1.bmp". Please could you try to isolate the cause ? JpegEncoder is very simple.

Or please could you share more information, like before and after log, Mat information ? (It is difficult to investigate without reproducible data.)

https://github.com/opencv/opencv/blob/4.9.0/modules/imgcodecs/src/grfmt_jpeg.cpp#L580

Appendix

There are different between source code and comment, so maybe it is hard to determine which is input Mat valid or invalid.

	//* These judgements don't work.
	if (t_frame[index].empty() || t_frame[index].dims <= 0 || t_frame[index].channels() <= 0) {
		std::cout << "Mat is invalid." << t_frame[index].cols << ",h:" << t_frame[index].rows << std::endl;
	}
	else {
		//* isContinuous: true type:16
		std::cout << "Mat is valid,w:" << t_frame[index].cols << ",h:" << t_frame[index].rows << std::endl;
		std::cout << "Mat isContinuous:" << t_frame[index].isContinuous() << ";type:" << t_frame[index].type() << std::endl;
	}

For Jpeg Encoder...

  • t_frame[index].empty() is needed.
  • t_frame[index].dims <= 0 should be t_frame[index].dims == 2. But usually it is not needed.
  • t_frame[index].channels() <= 0 should be check 1 or 3.
  • 1920x1080 is OK, but it is not checked.
  • isContinuous is not important because JpegEncoder handle each lines.
  • type:16 ( CV_8UC3 ) is OK, but it is not checked, only comment.

Hello, I'm sorry but if you want to ask question, https://forum.opencv.org/ is better. But because you said an exception that is not cv::Exception occurred, I comment it.

As the necessary information has not been shared sufficiently at this time, we are unable to investigate the cause. So I believe only you can investigate it .

As first, please could you split investigation in to 2 steps ?

  • Step1 ) Determine which is this problem in commonly part or Jpeg part.
  • Step2 ) (If jpeg part) Determine where line make exception.

Step1 ) Determine which is this problem in commonly part or Jpeg part.

"can't write data..." message is output from here. This is commonly part.

catch (const cv::Exception& e)
{
CV_LOG_ERROR(NULL, "imwrite_('" << filename << "'): can't write data: " << e.what());
}
catch (...)
{
CV_LOG_ERROR(NULL, "imwrite_('" << filename << "'): can't write data: unknown exception");
}

This is commonly part. Could you try with BMP encoder?

-	imwrite("1.jpg", t_frame[index]);
+	imwrite("1.bmp", t_frame[index]);

Step2 ) (If jpeg part) Determine where line make exception.

If this problem occurs with only "1.jpg", not "1.bmp". Please could you try to isolate the cause ? JpegEncoder is very simple.

Or please could you share more information, like before and after log, Mat information ? (It is difficult to investigate without reproducible data.)

https://github.com/opencv/opencv/blob/4.9.0/modules/imgcodecs/src/grfmt_jpeg.cpp#L580

Appendix

There are different between source code and comment, so maybe it is hard to determine which is input Mat valid or invalid.

	//* These judgements don't work.
	if (t_frame[index].empty() || t_frame[index].dims <= 0 || t_frame[index].channels() <= 0) {
		std::cout << "Mat is invalid." << t_frame[index].cols << ",h:" << t_frame[index].rows << std::endl;
	}
	else {
		//* isContinuous: true type:16
		std::cout << "Mat is valid,w:" << t_frame[index].cols << ",h:" << t_frame[index].rows << std::endl;
		std::cout << "Mat isContinuous:" << t_frame[index].isContinuous() << ";type:" << t_frame[index].type() << std::endl;
	}

For Jpeg Encoder...

  • t_frame[index].empty() is needed.
  • t_frame[index].dims <= 0 should be t_frame[index].dims == 2. But usually it is not needed.
  • t_frame[index].channels() <= 0 should be check 1 or 3.
  • 1920x1080 is OK, but it is not checked.
  • isContinuous is not important because JpegEncoder handle each lines.
  • type:16 ( CV_8UC3 ) is OK, but it is not checked, only comment.

imwrite_('1.bmp'): can't write data: unknown exception

How can I catch this error, at the moment the program just exits

from opencv.

Kumataro avatar Kumataro commented on June 5, 2024

@JianJingGao

Step1

I said you should try with BMP encoder instead of JPEG encoder.
How about it ? Does it works well?

And please notice that we cannot help you and/or debug your program because no one can reproduce your problem in other environment,
If you don't want to investigate/debug, this problem will not fixed forever. If so, It is better to close this issue.

(BTW a quoting all of previous comment is not meaning.)

from opencv.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.