deep-visualization-toolbox icon indicating copy to clipboard operation
deep-visualization-toolbox copied to clipboard

BGR->RGB convert issue

Open bairdzhang opened this issue 9 years ago • 4 comments

Hi,

After deploying this project successfully, I tried to run ./run_toolbox.py, but I got the following error and traceback:

  File "./run_toolbox.py", line 29, in <module>
    main()
  File "./run_toolbox.py", line 24, in main
    lv.run_loop()
  File "/home/zszhang/caffetoolbox/deep-visualization-toolbox/core.py", line 405, in run_loop
    self.display_frame(latest_frame_data)
  File "/home/zszhang/caffetoolbox/deep-visualization-toolbox/core.py", line 526, in display_frame
    self.panes['input'].data[:] = frame_disp
ValueError: could not broadcast input array from shape (270,270) into shape (270,270,3)

Then I read some of the source code, I found the im = im[:,:,::-1] may not work well on my system. I changed the im = im[:,:,::-1] to im = cv2.cvtColor(im, cv2.COLOR_BGR2RGB) in cv2_read_file_rgb and changed cv2.imshow(window_name, img[:,:,::-1]) to img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) and cv2.imshow(window_name, img) in cv2_imshow_rgb, then everything goes well (Only static image files are used).

I don't know whether it is a general issue or it happens because my system configuration is odd or incorrect. Any ideas?

Thanks, Baird

bairdzhang avatar Aug 10 '15 03:08 bairdzhang

@bairdzhang Thanks for reporting.

I think the root of the problem is that cv2.imread returns a 2D numpy array instead of 3D array. On my system it seems always to return a 3D array even for grayscale images. I pushed a fix for this to the dev branch (dcefb9a75); can you try it on your system?

yosinski avatar Aug 11 '15 20:08 yosinski

@yosinski The len(im.shape) is 3 for me before or after im = im[:,:,::-1].

And when I print im[1,1,:] before and after im = im[:,:,::-1], the channels do inverse. Before im = im[:,:,::-1], I can use imshow to show the image, however, after im = im[:,:,::-1], imshow cannot show the image and give this error message:

Bad flag (parameter or structure field) (Unrecognized or unsupported array type) in cvGetMat.

I'm using OpenCV 2.3.1, and It's really odd to happen that error.

bairdzhang avatar Aug 14 '15 09:08 bairdzhang

@bairdzhang hi,did you solve the problem? I get this:ValueError: could not broadcast input array from shape (300,300) into shape (300,300,3) Even though i changed the code as https://github.com/yosinski/deep-visualization-toolbox/commit/dcefb9a759b74cdf6cd30314d021cd5af099f5f4 If you solve the problem,can you please tell me ?

@yosinski Thanks for your great work! I want to run the original data as you provided,but when ./run_toolbox.py,i get the same error even i changed the code as you fixed.Can you help me with this issue?Thank you very much!

georgiazhang avatar Apr 28 '17 02:04 georgiazhang

@bairdzhang, @georgiazhang I've added support for grayscale based networks, and also for color based networks loading a grayscale image

Latest version is in https://github.com/arikpoz/deep-visualization-toolbox

arikpoz avatar Oct 16 '17 06:10 arikpoz