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

how to display masked result image? #11

Open
angyee opened this issue Jul 2, 2019 · 8 comments
Open

how to display masked result image? #11

angyee opened this issue Jul 2, 2019 · 8 comments

Comments

@angyee
Copy link

angyee commented Jul 2, 2019

i am getting results like this, but how to display the result of image?

[{'rois': array([[244, 287, 590, 721],
[216, 737, 426, 925]], dtype=int32), 'class': array([1, 1], dtype=int32), 'scores': array([0.9834276 , 0.76979005], dtype=float32), 'mask': array([[[False, False],
[False, False],
[False, False],
...,
[False, False],
[False, False],
[False, False]],

   [[False, False],
    [False, False],
    [False, False],
    ...,
    [False, False],
    [False, False],
    [False, False]],

   [[False, False],
    [False, False],
    [False, False],
    ...,
    [False, False],
    [False, False],
    [False, False]],

   ...,

   [[False, False],
    [False, False],
    [False, False],
    ...,
    [False, False],
    [False, False],
    [False, False]],

   [[False, False],
    [False, False],
    [False, False],
    ...,
    [False, False],
    [False, False],
    [False, False]],

   [[False, False],
    [False, False],
    [False, False],
    ...,
    [False, False],
    [False, False],
    [False, False]]])}]

@bendangnuksung @buaacarzp

@bendangnuksung
Copy link
Owner

mask value is a list of boolean numpy arrays, in order to convert it to an image and display you can use:

mask_val = result['mask'][0]
mask_image = mask_val.astype(np.uint8) * 255

@angyee
Copy link
Author

angyee commented Jul 4, 2019

mask value is a list of boolean numpy arrays, in order to convert it to an image and display you can use:

mask_val = result['mask'][0]
mask_image = mask_val.astype(np.uint8) * 255

edit required in forward.py? where?

@bendangnuksung

@angyee
Copy link
Author

angyee commented Jul 4, 2019

mask_val = r['mask'][0]
mask_image = mask_val.astype(np.uint8) * 255
#print(r)
cv2.imshow('mask', mask_image)
cv2.waitKey(0)
cv2.destroyAllWindows()

Traceback (most recent call last):
File "test.py", line 25, in
mask_val = r['mask'][0]
TypeError: list indices must be integers or slices, not str

@bendangnuksung

@bendangnuksung
Copy link
Owner

result is the variable you got after processing from the forward model.

result = [{'rois': array([[244, 287, 590, 721], [216, 737, 426, 925]], dtype=int32), 'class': array([1, 1], dtype=int32), 'scores': array([0.9834276 , 0.76979005], dtype=float32), 'mask': array([[[False, False], [False, False], [False, False], ...,

@angyee
Copy link
Author

angyee commented Jul 4, 2019

result is the variable you got after processing from the forward model.

result = [{'rois': array([[244, 287, 590, 721], [216, 737, 426, 925]], dtype=int32), 'class': array([1, 1], dtype=int32), 'scores': array([0.9834276 , 0.76979005], dtype=float32), 'mask': array([[[False, False], [False, False], [False, False], ...,

mask_val = r['mask'][0]
change required
mask_val = r[0]['mask]

but error is

Traceback (most recent call last):
File "test.py", line 29, in
cv2.imshow('mask', mask_image)
cv2.error: OpenCV(4.1.0) /io/opencv/modules/imgproc/src/color.simd_helpers.hpp:92: error: (-2:Unspecified error) in function 'cv::impl::{anonymous}::CvtHelper<VScn, VDcn, VDepth, sizePolicy>::CvtHelper(cv::InputArray, cv::OutputArray, int) [with VScn = cv::impl::{anonymous}::Set<3, 4>; VDcn = cv::impl::{anonymous}::Set<3, 4>; VDepth = cv::impl::{anonymous}::Set<0, 2, 5>; cv::impl::{anonymous}::SizePolicy sizePolicy = (cv::impl::::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 2

@bendangnuksung
Copy link
Owner

bendangnuksung commented Jul 4, 2019

convert it to mask_val = r[0]['mask'][0] and see

@angyee
Copy link
Author

angyee commented Jul 4, 2019

convert it to mask_val = r[0]['mask'][0] and see

above line is working but, I have to show a masked image on my input image like this:

splash_20190611T122947

@bendangnuksung @bendangnuksung

@angyee
Copy link
Author

angyee commented Jul 9, 2019

from forward import ForwardModel
import cv2
import numpy as np

frozen_graph_path = "/home/deepedge/mask_rcnn-master/mask_dent_frozen_graph.pb"

assign your own Config class

from config import mask_config
my_config = mask_config(1)

forward_model = ForwardModel(frozen_graph_path, my_config)

def test_one_image(image):
images = np.expand_dims(image, axis=0)
#print(images)
results = forward_model(images)
return results

if name == "main":
test_image_path = '/home/deepedge/mask_rcnn-master/mask-rcnn-bottle-training-master/dataset/val/car39.jpg'
image = cv2.imread(test_image_path)
rr = test_one_image(image)
from mrcnn import visualize
from mrcnn import model
r = model.detect([rr], verbose=0)[0]
visualize.display_instances(rr, r['rois'], r['masks'], r['class_ids'],
dataset.class_names, r['scores'])
print(type(r))

i have used There is a function called "display_instances" in the script "mrcnn/visualize.py" to visualize the results :
not working?
@bendangnuksung

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants