Skip to content

Commit

Permalink
use cv2 to imread
Browse files Browse the repository at this point in the history
  • Loading branch information
ddshan committed Nov 6, 2020
1 parent 57977d6 commit 2094bd1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
13 changes: 4 additions & 9 deletions demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import torchvision.transforms as transforms
import torchvision.datasets as dset
from scipy.misc import imread
# from scipy.misc import imread
from roi_data_layer.roidb import combined_roidb
from roi_data_layer.roibatchLoader import roibatchLoader
from model.utils.config import cfg, cfg_from_file, cfg_from_list, get_output_dir
Expand Down Expand Up @@ -260,14 +260,9 @@ def _get_image_blob(im):
# Load the demo image
else:
im_file = os.path.join(args.image_dir, imglist[num_images])
im_in = np.array(imread(im_file))
# resize
# im_in = np.array(Image.fromarray(im_in).resize((640, 360)))
if len(im_in.shape) == 2:
im_in = im_in[:,:,np.newaxis]
im_in = np.concatenate((im_in,im_in,im_in), axis=2)
# rgb -> bgr
im = im_in[:,:,::-1]
im_in = cv2.imread(im_file)
# bgr
im = im_in

blobs, im_scales = _get_image_blob(im)
assert len(im_scales) == 1, "Only single-image batch implemented"
Expand Down
16 changes: 9 additions & 7 deletions lib/roi_data_layer/minibatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
from __future__ import division
from __future__ import print_function

import cv2
import numpy as np
import numpy.random as npr
from scipy.misc import imread
# from scipy.misc import imread
from model.utils.config import cfg
from model.utils.blob import prep_im_for_blob, im_list_to_blob
import pdb
Expand Down Expand Up @@ -70,15 +71,16 @@ def _get_image_blob(roidb, scale_inds):
processed_ims = []
im_scales = []
for i in range(num_images):
#im = cv2.imread(roidb[i]['image'])
im = imread(roidb[i]['image'])
im = cv2.imread(roidb[i]['image'])
# im = imread(roidb[i]['image'])

if len(im.shape) == 2:
im = im[:,:,np.newaxis]
im = np.concatenate((im,im,im), axis=2)
# if len(im.shape) == 2:
# im = im[:,:,np.newaxis]
# im = np.concatenate((im,im,im), axis=2)
# flip the channel, since the original one using cv2
# rgb -> bgr
im = im[:,:,::-1]
# im = im[:,:,::-1]


if roidb[i]['flipped']:
im = im[:, ::-1, :]
Expand Down

0 comments on commit 2094bd1

Please sign in to comment.