I am getting a Open cv error when working with object detection

object detection opencv python
opencv object detection
real-time object detection opencv python
object detection opencv c++
object detection opencv c++ github
custom object detection opencv
object detection python
tensorflow object detection
import cv2
import numpy as np
from random import shuffle
from tqdm import tqdm
import os

TRAIN_DIR=r'C:\Users\Valued Customer\Desktop\Object detection\train'
TEST_DIR=r'C:\Users\Valued Customer\Desktop\Object detection\test'
IMG_SIZE=300
LR=1e-3
MODEL_NAME = 'dogsvscats-{}-{}.model'.format(LR,'2conv-basic')



def Label_img(img):
    label = img.split('.')[-3]
    if label == 'cat':
        return [1,0]
    elif label == 'dog':
        return [0,1]

def create_train_data():
    training_data = []
    for img in tqdm(os.listdir(TRAIN_DIR)):

        label = Label_img(img)
        path = os.path.join(TRAIN_DIR,img)
        img = cv2.resize(cv2.imread(path),(IMG_SIZE,IMG_SIZE), interpolation = cv2.INTER_AREA)
        training_data.append([np.array(img),np.array(label)])
    shuffle(training_data)
    np.save('train_data.npy',training_data)
    return training_data

def process_test_data():
    testing_data = []
    for img in tqdm(os.listdir(TEST_DIR)):
        path = os.path.join(TEST_DIR,img)
        img_num = img.split('.')[0]
        img = cv2.resize(cv2.imread(path),(IMG_SIZE,IMG_SIZE), interpolation = cv2.INTER_AREA)

        testing_data.append([np.array(img),img_num])
    np.save('testing_data.npy',testing_data)
    return testing_data

train_data = create_train_data()
#if U already have train data then:
#train_data = np.load('train_data.npy',allow_pickle=True)
print('data has been loaded')

import tflearn
from tflearn.layers.conv import conv_2d,max_pool_2d
from tflearn.layers.core import input_data,dropout,fully_connected
from tflearn.layers.estimator import regression
from tflearn.layers.normalization import batch_normalization as bn
import tensorflow as tf
tf.reset_default_graph()

convnet = input_data(shape=[None,IMG_SIZE,IMG_SIZE,3],name='input')

convnet = conv_2d(convnet,32,filter_size=[2,2],activation='relu')
convnet = conv_2d(convnet,64,filter_size=[2,2],activation='relu')
convnet = bn(convnet,trainable=True)
convnet = max_pool_2d(convnet,kernel_size=[3,3])

convnet = conv_2d(convnet,32,filter_size=[2,2],activation='relu')
convnet = conv_2d(convnet,64,filter_size=[2,2],activation='relu')
convnet = bn(convnet,trainable=True)
convnet = max_pool_2d(convnet,kernel_size=[3,3])

convnet = conv_2d(convnet,32,filter_size=[2,2],activation='relu')
convnet = conv_2d(convnet,64,filter_size=[2,2],activation='relu')
convnet = bn(convnet,trainable=True)
convnet = max_pool_2d(convnet,kernel_size=[3,3])

convnet = fully_connected(convnet,1024,activation='relu')
convnet = dropout(convnet,0.8)
convnet = tflearn.layers.normalization.batch_normalization(convnet,trainable=True)


convnet = fully_connected(convnet,2,activation='softmax')
convnet = regression(convnet,
                     optimizer='adam',
                     learning_rate= LR,
                     loss='categorical_crossentropy',
                     name='targets')

model = tflearn.DNN(convnet)

train = train_data[:-500]
test = train_data[-500:]

X = np.array([i[0] for i in train]).reshape(-1,IMG_SIZE,IMG_SIZE,3)
Y = np.array([i[1] for i in train])

test_x = np.array([i[0] for i in test]).reshape(-1,IMG_SIZE,IMG_SIZE,3)
test_y = np.array([i[1] for i in test])

model.fit({'input':X},{'targets':Y},
          n_epoch=5,validation_set=({'input':test_x},{'targets':test_y}),
          snapshot_step=500,show_metric=True,run_id=MODEL_NAME)
#
model.save(MODEL_NAME)





When ever I try to run this code it stops a 21% when it is creating the training data

def create_train_data():
    training_data = []
    for img in tqdm(os.listdir(TRAIN_DIR)):

        label = Label_img(img)
        path = os.path.join(TRAIN_DIR,img)
        img = cv2.resize(cv2.imread(path),(IMG_SIZE,IMG_SIZE), interpolation = cv2.INTER_AREA)

And it keeps giving em a open cv error

error: OpenCV(4.1.1) C:\projects\opencv-python\opencv\modules\imgproc\src\resize.cpp:3720: error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize

I am on windows ten using cuda for the first (not sure if i set it up right) Also does anyone know how i can check if i am using cuda Thanks

I got this error today because my path of images was not right.U can try to show one image to see whether you read the image successfully.

object_detection.cpp gives some error with Faster rcnn inception v2 , I am working on object detection with the following sample in opencv dnn I generate pbtxt file for my inception model. and now I get this error:. Keep in mind, the background subtraction is to see what pixels are moving, if you want to track an object, you have to perform a tracking of this object, with blob or anything else. [Update] For vehicles detection, there is many workflows. Some of them are even not using background subtraction. You could Google it if your are interested.

So i found a answer to my own question!!!

What i did was print the names of the that it was loading in and the image that it stopped on was corrupt. I had to this multiple times.

Object detection with deep learning and OpenCV, Learn how to apply object detection using deep learning, Python, and OpenCV Now Coming back to the Topic , I'm Getting this error : Is there any way to make this work with OpenCV 3.2 – I am trying to make this work� In this tutorial we are going to use those algorithms to detect real life objects, here we would be using SIFT and ORB for the detection. Object detection using SIFT. Here object detection will be done using live webcam stream, so if it recognizes the object it would mention objet found. In the code the main part is played by the function which

Just type this your script or ipython cell to verify if there is an empty or corrupt image that might create this error .

import os
from PIL import Image

img_dir = r"/content/downloads/Cars"
for filename in os.listdir(img_dir):
    try :
        with Image.open(img_dir + "/" + filename) as im:
             print('ok')
    except :
        print(img_dir + "/" + filename)
        os.remove(img_dir + "/" + filename)

Replace img_dir to the directory name from where you are trying to resize the images. Hope it was helpful .

Real-time object detection with deep learning and OpenCV , In this tutorial I demonstrate how to apply object detection with deep learning object Duration: 0:56 Posted: Sep 18, 2017 Raspberry Pi: Deep learning object detection with OpenCV. Today’s blog post is broken down into two parts. In the first part, we’ll benchmark the Raspberry Pi for real-time object detection using OpenCV and Python. This benchmark will come from the exact code we used for our laptop/desktop deep learning object detector from a few weeks ago.

Yolo object detection webcam opencv error, I have the same error as you. when I try to follow this tutorial to install opencv3.4 manually,re-make and it works. But remember the version of� First, a classifier (namely a cascade of boosted classifiers working with haar-like features) is trained with a few hundred sample views of a particular object (i.e., a face or a car), called positive examples, that are scaled to the same size (say, 20x20), and negative examples - arbitrary images of the same size.

How to fix no Qt plugin initialized error for OpenCV People Counter , qt opencv cocoa terminal. I am trying to get a working setup of the object detection and tracking algorithm talked about in this tutorial:� so I'm really new here. Currently working on a public art project where I need a little help with the programming because I'm kind off lost between codes. First I'll give you a short description of the goal of the work and then state my problem. I'm putting a webcam in the shopwindow of a gallery that is facing out on a public street.

YOLO Object Detection with OpenCV and Python, Object detection using OpenCV dnn module with a pre-trained YOLO v3 It's just for running inference on images/videos. If you are feeling overwhelmed by the instructions to get OpenCV Feel free to share your thoughts in the comments or you can reach Using IDLE, getting error for the above code. The names of the objects that our model has been trained to identify is given in the “coco.names” file, which we store in a list called classes. We also retrieve the names of the output layers with the help of the getLayerNames() and getUnconnectedOutLayers() function and store them too in output_layers list.

Comments
  • I already checked that So im assuming that it is not the problem