gpt4 book ai didi

oracle - 使用 SQL/MM Still Image 将 BLOB 图像与存储为 ORDImage 的图像进行比较

转载 作者:行者123 更新时间:2023-12-01 23:34:15 25 4
gpt4 key购买 nike

我正在使用 Oracle 11g r2

我有一个表,将图像存储为 ORDImage :

PHOTOS (phot_id integer
, phot_filename varchar2(256)
, phot_source ordsys.ordimage)

另一个临时表将用户上传的图像存储为 BLOB

INSERT_TEMP (itemp_id integer, itemp_source blob)

我想通过比较两个图像将 BLOB 图像移动到 PHOTOS 表(如果不存在)。我需要使用 SQL/MM Still Image 方法,因为 ORDImageSignature 方法在 Oracle 11g 中已弃用。

代码如下:

 declare
[...]
begin
[...]
-- get the blob from the temporary table (in_id passed as parameter)
select itemp_source into l_img_blob from insert_temp where itemp_id = in_id;
-- build the stillimage object from the blob
l_img_obj := new si_stillimage(l_img_blob);
-- get image features and build the featureList object
l_avgcolor := new si_averagecolor(l_img_obj);
l_colorhist := new si_colorhistogram(l_img_obj);
l_poscolor := new si_positionalcolor(l_img_obj);
l_texture := new si_texture(l_img_obj);
l_featurelist := new SI_FeatureList(l_avgcolor, 1, l_colorhist, 1, l_poscolor, 1, l_texture, 1);
-- check if a similar image already exists
select count(*) into l_exist from photos p where SI_ScoreByFtrList(l_featurelist, SI_MkStillImage1(p.phot_source.source.localdata)) = 0;
if (l_exist > 0) then
out_message := app_util.get_translated_message('ERR_SIMILAR_PHOTO_ALREADY_EXISTS');
else
/* here the blob is inserted into the PHOTOS table as ORDImage successfully */
out_message := app_util.get_translated_message('SUC_PHOTO_INSERTED');
end if;
end;

如果我省略比较,图像将作为 ORDImage 成功插入,否则会引发异常(sqlcode: 1, sqlerrm: User-defined Exception),使用 DBMS_UTILITY.FORMAT_ERROR_BACKTRACE 它告诉我以下内容:

ORA-06512: à "ORDSYS.SI_STILLIMAGE", ligne 27
ORA-06512: à "ORDSYS.SI_MKSTILLIMAGE1", ligne 6
ORA-06512: à "SURV.APP_CORE", ligne 212

第 212 行是检查相似图像是否已存在的行:

 select count(*) into l_exist
from photos p
where SI_ScoreByFtrList(l_featurelist, SI_MkStillImage1(p.phot_source.source.localdata)) = 0;

问题似乎是它不接受 p.phot_source.source.localdata 作为参数。您知道我该如何解决这个问题吗?

我也试过:

 select count(*) into l_exist 
from photos p
where l_featurelist.si_score(new si_stillimage1(p.phot_source.source.localdata)) = 0;

谢谢!

最佳答案

我终于回到了问题上,让它开始工作。

问题很简单,我在 ORDImage 字段中有一些 null 值...


我通过尝试将 StillImage 对象直接存储到我的 PHOTOS 表中发现了我的错误:

alter table PHOTOS add phot_source2 SI_Stillimage;
update photos p set p.phot_source2 = si_stillimage(p.phot_source.source.localData) where p.phot_id < 10;

然后实现以下最小示例:

DECLARE
l_img_obj si_stillimage;
l_avgcolor si_averagecolor;
l_colorhist si_colorhistogram;
l_poscolor si_positionalcolor;
l_texture si_texture;
l_featurelist si_featurelist;
l_blob BLOB;
l_exist INTEGER;
BEGIN
-- get the blob from the ordimage
SELECT p.phot_source.source.localdata
INTO l_blob FROM photos p
WHERE phot_id = 2;
-- build the stillimage object from the blob
l_img_obj := NEW si_stillimage(l_blob);
-- get image features and build the featureList object
l_avgcolor := NEW si_averagecolor(l_img_obj);
l_colorhist := NEW si_colorhistogram(l_img_obj);
l_poscolor := NEW si_positionalcolor(l_img_obj);
l_texture := NEW si_texture(l_img_obj);
l_featurelist := NEW si_featurelist(l_avgcolor, 1, l_colorhist, 1, l_poscolor, 1, l_texture, 1);
-- check if a similar image is found in the table
SELECT 1
INTO l_exist
FROM photos p
WHERE si_scorebyftrlist(l_featurelist, p.phot_source2) = 0
AND phot_id < 10
AND rownum = 1;
-- show message if at least one similar photo has been found
IF (l_exist = 1) THEN
dbms_output.put_line('A similar photo has been found');
END IF;
END;
/

phot_id 限制为 10 时工作正常,即使将 p.phot_source2 替换为 si_mkstillimage1(p.phot_source.source.localdata)(这是导致问题的原因)。但是在删除 phot_id 限制时失败了。所以我终于明白我在 phot_source 列 (ORDImage) 中有一些 null 值可能会导致问题。

并且确实调用带有null 参数的SI_StillImage() 构造函数会导致以下错误消息:

ORA-06510: PL/SQL: unhandled user-defined exception
ORA-06512: at "ORDSYS.SI_STILLIMAGE", line 27
ORA-06512: at "ORDSYS.SI_MKSTILLIMAGE1", line 6
ORA-06512: at line 24

我从 phot_source 列中删除了所有 null 值,现在一切正常:)


更进一步:

这样做的缺点是与表中存储的所有图像进行比较需要很长时间(1155 秒(大约 20 分钟) 5000 照片)。所以我尝试将图像特征直接存储到表中:

alter table photos add (
phot_averagecolor si_averagecolor,
phot_colorhistogram si_colorhistogram,
phot_positionalcolor si_positionalcolor,
phot_texture si_texture
)

update photos p set
p.phot_averagecolor = si_averagecolor(si_stillimage(p.phot_source.source.localData)),
p.phot_colorhistogram = si_colorhistogram(si_stillimage(p.phot_source.source.localData)),
p.phot_positionalcolor = si_positionalcolor(si_stillimage(p.phot_source.source.localData)),
p.phot_texture = si_texture(si_stillimage(p.phot_source.source.localData))
where p.phot_id < 10

然后像这样进行比较:

-- get the blob from the ordimage
SELECT p.phot_source.source.localdata
INTO l_blob FROM photos p
WHERE phot_id = 2;
-- build the stillimage object from the blob
l_img_obj := NEW si_stillimage(l_blob);
-- get image features and build the featureList object
l_avgcolor := si_averagecolor(l_img_obj);
l_colorhist := si_colorhistogram(l_img_obj);
l_poscolor := si_positionalcolor(l_img_obj);
l_texture := si_texture(l_img_obj);
l_featurelist := NEW si_featurelist(l_avgcolor, 1, l_colorhist, 1, l_poscolor, 1, l_texture, 1);
-- check if a similar image is found in the table
SELECT 1
INTO l_exist
FROM photos p
WHERE p.phot_averagecolor = l_avgcolor
AND p.phot_colorhistogram = l_colorhist
AND p.phot_positionalcolor = l_poscolor
AND p.phot_texture = l_texture
AND p.phot_id < 10
AND rownum = 1;

但它给出了以下错误,因为似乎无法直接使用 = 运算符比较图像特征:

ORA-22901: cannot compare VARRAY or LOB attributes of an object type
ORA-06512: at line 24

我认为一个解决方案是将图像特征存储为数值,但我阅读了整个 documentation而且我还没有找到任何方法从图像特征中获取任何相应的数值。

幸运的是,为每个图像特征提供了SI_score 函数,因此我们可以使用以下方法来比较图像:

DECLARE
l_img_obj si_stillimage;
l_blob BLOB;
l_exist INTEGER;
BEGIN
-- get the blob from the ordimage
SELECT p.phot_source.source.localdata
INTO l_blob FROM photos p
WHERE phot_id = 2;
-- build the stillimage object from the blob
l_img_obj := NEW si_stillimage(l_blob);
-- check if a similar image is found in the table
SELECT 1
INTO l_exist
FROM photos p
WHERE p.phot_averagecolor.SI_Score(l_img_obj) = 0
AND p.phot_colorhistogram.SI_Score(l_img_obj) = 0
AND p.phot_positionalcolor.SI_Score(l_img_obj) = 0
AND p.phot_texture.SI_Score(l_img_obj) = 0
AND rownum = 1;
-- show message
dbms_output.put_line(l_count || ' similar photo(s) found');
END;
/

我将 5000 图片的时间从 1155 秒(大约 20 分钟) 减少到 226 秒(不到 3 分钟)

我知道,它仍然很慢,但我找不到其他方法来提高性能...,如果有人有想法,请不要犹豫分享。

关于oracle - 使用 SQL/MM Still Image 将 BLOB 图像与存储为 ORDImage 的图像进行比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9893809/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com