Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug cvui:image() crash when size of image is larger from canvas #94

Open
mwindowshz opened this issue Jul 1, 2020 · 3 comments
Open
Labels
bug c++ Issues related to the C++ version of cvui python Issues related to the Python version of cvui

Comments

@mwindowshz
Copy link

I found a bug, and it is occurring in different scenarios

first scenario - drawing image on a smaller canvas

cvui::image(frame, 0, 0, map);
calling cvui::image, when frame size is 1280x720 (width, height)
and the map image is larger, theRect is 1480x840
then the call to image() crashes on theImage.copyTo(theBlock.where(theRect));
int function render::image(theBlock, aRect, theImage);

the size of theRect is larger then theBlock!
need to resize, or not crash

when using movable EnhancedWindow with an image inside of it , and it is dragged out of frame

in this case, theRect has for example x=-10,y=10 if I drag it to the left , so the program crashes on same issue
cvui::image() on theImage.copyTo(theBlock.where(theRect));

I tried adding if statement to resolve crashing,

void image(cvui_block_t& theBlock, cv::Rect& theRect, cv::Mat& theImage) {
		if (theRect.x < 0 || theRect.y <0 || theRect.y  + theRect.height > theBlock.where.rows)
			return;
		theImage.copyTo(theBlock.where(theRect));
	}

But this does not give good beheivior because for example trying to draw larger image , just does not draw anything. maybe larger image should be resized?
It fixed the issue of dragging the window with an image. but it did not cover all ways the window is dragged.

Hope there is a solution
Thanks in advance
M.

@Dovyski Dovyski added bug c++ Issues related to the C++ version of cvui python Issues related to the Python version of cvui labels Jul 13, 2020
@Dovyski
Copy link
Owner

Dovyski commented Jul 13, 2020

Thanks for the bug report. I think this problem you reported happens in different parts of cvui as well, when a frame to be rendered is larger than the available space, e.g. window area. I'll try to fix this problem by cropping the are that should not be displayed.

@mwindowshz
Copy link
Author

Hi
this is how I fixed this

void image(cvui_block_t& theBlock, cv::Rect& theRect, cv::Mat& theImage) {
		if (theRect.x < 0 || theRect.y <0 ||theRect.x + theRect.width > theBlock.where.cols || theRect.y  + theRect.height > theBlock.where.rows)
			return;
		theImage.copyTo(theBlock.where(theRect));
	}

added this If statement you can check if this is correct and covers all the issues.

@Dovyski
Copy link
Owner

Dovyski commented Jul 21, 2020

Thanks, that's a great starting point for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug c++ Issues related to the C++ version of cvui python Issues related to the Python version of cvui
Projects
None yet
Development

No branches or pull requests

2 participants