Typography-with-Decor icon indicating copy to clipboard operation
Typography-with-Decor copied to clipboard

Opencv Error when execute runtest.py

Open justfouw opened this issue 5 years ago • 10 comments

I run python runtest.py. The style-content pair is face-lan. The error is on cv2.resize(), It seems that this input image has an invalid shape.

In addition, Could you provide the specified version of workspace, such as the version of pytorch, opencv, etc.

File "decor_recomposition.py", line 452, in Move
    deco = cv2.resize(deco,(new_size_y,new_size_x))
cv2.error: OpenCV(3.4.5) /io/opencv/modules/imgproc/src/resize.cpp:3787: error: (-215:Assertion failed) inv_scale_x > 0 in function 'resize'

justfouw avatar Jun 18 '19 08:06 justfouw

''' Process the 0-th class, containing 447 elements...............Traceback (most recent call last): File "decor_recomposition.py", line 609, in result, input_map, output_map, input_dir_map, output_dir_map = GOT.Move(Img,Cha,Seg,TargetImg,TargetCha, opt.style name, opt.content_name) File "decor_recomposition.py", line 436, in Move deco = cv2.resize(deco,(new_size_y,new_size_x)) cv2.error: OpenCV(3.4.3) /io/opencv/modules/imgproc/src/resize.cpp:4045: error: (-215:Assertion failed) !dsize.empty() || (inv_scale_x > 0 && inv_scale_y > 0) in function 'resize' '''

Hi. I have similar error with opencv. Please share the version that you are using.

bado-lee avatar Jun 25 '19 04:06 bado-lee

@justfouw Hi, any luck with this problem?

bado-lee avatar Jun 25 '19 04:06 bado-lee

@bado-lee It is not an issue of the opencv version. The h,w passed to function resize() is 0. Thus, some boundary protection operations will be useful. such as

...
h = max(h, 1)
w = max(w, 1)
...

justfouw avatar Jun 25 '19 04:06 justfouw

@justfouw Thank you for your comment. I'll try your suggestion.

bado-lee avatar Jun 25 '19 04:06 bado-lee

image weird it's holding there... @justfouw Were you successful running the "runtest.py" ?

bado-lee avatar Jun 25 '19 04:06 bado-lee

@justfouw it seems like it falls into infinite loop. after applying protective operation...

decor_recomposition.py : while(x_start<5 or y_start<5 or x_end>output_img.shape[0]-5 or y_end>output_img.shape[1]-5):

bado-lee avatar Jun 25 '19 05:06 bado-lee

I was able to run runtest.py after a bit of modification. Simply check new_size validity before resizing. If it's not valid, continue. Hope this will help someone. Anyhow, my test result with custom data was not as good as expected. It finds basal patterns as decor.

# git diff decor_recomposition.py
diff --git a/decor_recomposition.py b/decor_recomposition.py
index 1793b4b..8baa998 100644
--- a/decor_recomposition.py
+++ b/decor_recomposition.py
@@ -400,6 +400,10 @@ class GetObjectTool():
                     new_size_ratio = (elements_num_ratio * (0.75+random.random()/2)) ** 0.2
                     new_size_x = int(mask.shape[0] * new_size_ratio)
                     new_size_y = int(mask.shape[1] * new_size_ratio)
+
+                    if new_size_x < 1 or new_size_y < 1:
+                        continue
+
                     mask = mask / 255.
                     mask = cv2.resize(mask,(new_size_x,new_size_y))
                     deco = decorationClass[cur_num]['Object']
@@ -433,6 +437,9 @@ class GetObjectTool():
                     new_size_x = int(new_size_x * reshape_ratio)
                     new_size_y = int(new_size_y * reshape_ratio)

+                    if new_size_x < 1 or new_size_y < 1:
+                        continue
+
                     deco = cv2.resize(deco,(new_size_y,new_size_x))
                     mask = cv2.resize(mask,(new_size_y,new_size_x))

@@ -449,6 +456,10 @@ class GetObjectTool():
                         new_size_x = int(new_size_x * 0.95)
                         new_size_y = int(new_size_y * 0.95)

+                        if new_size_x < 1 or new_size_y < 1:
+                            beyoung_boundary = True
+                            break
+
                         deco = cv2.resize(deco,(new_size_y,new_size_x))
                         mask = cv2.resize(mask,(new_size_y,new_size_x))

bado-lee avatar Jun 26 '19 07:06 bado-lee

Hi, bado-lee, even though I modified the code as you adviced, the following issue occured:

Traceback (most recent call last): File "decor_recomposition.py", line 616, in result, input_map, output_map, input_dir_map, output_dir_map = GOT.Move(Img,Cha,Seg,TargetImg,TargetCha, opt.style_name, opt.content_name) File "decor_recomposition.py", line 418, in Move covering_shape_before = input_thickness_map[input_x_start:input_x_end,input_y_start:input_y_end] * mask ValueError: operands could not be broadcast together with shapes (9,6) (9,7) Process the 0-th class, containing 492 elements.'rm' is not recognized as an internal or external command, operable program or batch file. Traceback (most recent call last): File "E:/Ray/Jupyter/Typography-with-Decor-master/Typography-with-Decor-master/runtest.py", line 42, in os.mkdir('temp') FileExistsError: [WinError 183] Cannot create a file when that file already exists: 'temp'

xphsean12 avatar Jul 02 '19 07:07 xphsean12

@xphsean12 I didn't face the same issue. However, the error is because of dimension mismatch between "input_thinkness_map" and the "mask" I think this is the error that should be debugged. Anyways, you can bypass the situation by adding

if input_thickness_map.shape != mask.shape:
    continue

just before line 418. but no guarantee. you can try... :)

bado-lee avatar Jul 02 '19 08:07 bado-lee

@bado-lee

Thanks! It hepls.

xphsean12 avatar Jul 02 '19 09:07 xphsean12