我可以构建一个只有一个类(即西瓜)的图像分类器吗

发布于 2025-01-09 17:42:04 字数 1298 浏览 1 评论 0原文

我对此很陌生,所以我真的不知道该怎么做。

我有这个西瓜数据集,我想创建一个图像分类器,根据数据集的特征判断输入图像是否是西瓜。

我尝试执行 ORB,循环遍历数据集中的所有图像,并尝试获取每个图像的描述符并将它们附加到列表中。

imagePaths = list(paths.list_images('...'))

orb = cv.ORB_create(nfeatures=1000)

keyPoints = []
descriptors = []

for imagePath in imagePaths:
    image = cv.imread(imagePath, 0)
    key_points, descriptor = orb.detectAndCompute(image, None)
    keyPoints.append(key_points)
    descriptors.append(descriptor)

然后我读取输入图像并使用 ORB 获取描述符。

test = cv.imread('apple_158989157.jpg', 0)
keypoint_test, desc_test = orb.detectAndCompute(test, None)

获得描述符后,我使用 BFMatcher 来匹配数据集和输入图像之间的描述符。循环遍历列表中存储的描述符并将其与输入图像的描述符进行匹配

bf = cv.BFMatcher()
for descriptor in descriptors:
        matches = bf.knnMatch(desc_test , descriptor, k = 2)

        for m, n in matches:
            if m.distance < 0.75 * n.distance:
                goodMatches.append([m])

为了知道它是否是西瓜,我声明了一个阈值。

threshold = 1500
if len(goodMatches) > threshold:
        print('Watermelon found!')
    else:
        print('No watermelon found!')

我尝试在 18 种不同的水果和 10 个西瓜上使用这些,18 个中的 18 个被分类为“非西瓜”,10 个西瓜中有 2 个被分类为“非西瓜”。

但是,是否有任何方法或更好的方法可以让图像分类器仅包含一个类别?

附言。我有 120 张西瓜图像作为数据集。

I'm new to this so I don't really know what to do.

I have this dataset of watermelon and I want to create an image classifier that tells whether the input image is watermelon or not based on the features of the dataset.

I tried doing ORB where I loop through all the images in the dataset and try to get the descriptors of each image and append them to the list.

imagePaths = list(paths.list_images('...'))

orb = cv.ORB_create(nfeatures=1000)

keyPoints = []
descriptors = []

for imagePath in imagePaths:
    image = cv.imread(imagePath, 0)
    key_points, descriptor = orb.detectAndCompute(image, None)
    keyPoints.append(key_points)
    descriptors.append(descriptor)

Then I read the input image and also get the descriptor using ORB.

test = cv.imread('apple_158989157.jpg', 0)
keypoint_test, desc_test = orb.detectAndCompute(test, None)

After I get the descriptors I use BFMatcher to match the descriptors between the dataset and the input image. Looping through the descriptors stored in the list and matching it with the descriptor of the input image

bf = cv.BFMatcher()
for descriptor in descriptors:
        matches = bf.knnMatch(desc_test , descriptor, k = 2)

        for m, n in matches:
            if m.distance < 0.75 * n.distance:
                goodMatches.append([m])

In order to know if it is watermelon or not I declare a threshold.

threshold = 1500
if len(goodMatches) > threshold:
        print('Watermelon found!')
    else:
        print('No watermelon found!')

I tried using these on 18 different fruits and 10 watermelons, 18 out of 18, it classifies it as Not watermelon, and 2 out of 10 watermelons were classified as Not Watermelon.

However, is there any method or a better way to have an image classifier with one class only?

PS. I have 120 images of watermelon as dataset.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文