Как найти y -осевое совместное сходство в двух изображениях?

По умолчанию пакет mcelog устанавливает демон, который переводит MCE в человекочитаемую форму и записывает их в системные журналы. Вы можете просмотреть их в /var/log/syslog или с помощью journalctl. Демон запускается из init-скрипта, нет необходимости добавлять для него блок systemd.

Однако маловероятно, что проблемы с веб-камерой, которые вы наблюдаете, могут вызвать MCE, поэтому я сомневаюсь, что это вам поможет. Устройство, указанное как input для mcelog, не является устройством ввода, это специальное устройство, используемое для связи между ядром и всем, что заинтересовано в MCEs (mcelog в данном случае).

6
17.04.2017, 09:02
2 ответа

Hugin сошьет эти изображения для вас.

В руководстве по объединению отсканированных изображений есть скрипт, который называется run-scan-pto_var.sh, и он сделает именно то, что вам нужно.

В моей системе Debian мне нужно установить два пакета (и, конечно же, их зависимости):

apt-get install hugin hugin-tools

В интересах полноты вопроса я включил сюда слегка измененную версию (эта версия принимает имена файлов изображений по команде строка вместо того, чтобы их жестко запрограммировать):

#! /bin/sh
# hugin command tools script to stitch scanned images, fov unknown
# use of fov >= 10 should be OK, could simply set FOV=10
# Terry Duell 2013, 2014

# usage...run-scan-pto_var.sh outputprefix fov

#get the output file prefix
Prefix=$1

# get the fov
FOV=$2

shift 2

pto_gen --projection=0 --fov=$FOV -o project.pto "$@"
pto_lensstack -o project1.pto --new-lens i1 project.pto
cpfind -o project1.pto --multirow project1.pto
cpclean -o project2.pto project1.pto
linefind -o project3.pto project2.pto
pto_var -o setoptim.pto --opt r,d,e,!r0,!d0,!e0 project3.pto
autooptimiser -n -o autoptim.pto setoptim.pto
pano_modify  --projection=0 --fov=AUTO --center --canvas=AUTO --crop=AUTO -o autoptim2.pto autoptim.pto
pto2mk -o project.mk -p $Prefix autoptim2.pto
make -j 2 -f project.mk all

# Clean up afterwards
rm -f project.pto project1.pto project2.pto project2.pto project.mk
rm -f "$Prefix"[0-9][0-9][0-9][0-9].tif
rm -f autoptim.pto autoptim2.pto autoptim2.pto_rsp.arg
rm -f setoptim.pto

Если ваши изображения называются wIowW.jpg и илиMDp.jpg — как ваши имена — и вы хотите, чтобы результат был в rsp.tif вы можете запустить скрипт следующим образом:

./run-scan-pto_var.sh rsp 10 *.jpg

Вывод всегда записывается в файл TIFF. Однако этот формат тривиально преобразуется практически в любой другой формат изображения.

Результат?

enter image description here

3
27.01.2020, 20:28

Отредактированный и обновленный скрипт:

Это решение основано на исходных изображениях. Он объединит два изображения любой высоты, но ширина двух входных изображений должна совпадать.

Вы бы назвали этот скрипт так:

sh ./name-of-script topImg.jpg bottomImg.jpg

Два входных изображения проверяются на совпадение сечения пересечения. Если это совпадение не найдено, сценарий завершится.

Для работы требуется только ImageMagick.

#!/bin/sh
#
# Assume (based on the test images) that the input images are "part of" a
# single image. If not, this will not work :] 
#

# Compare threshold - a value from 0 (100% match) to 100 (nothing alike).
# A low value is a good idea
THRESHOLD=5

# We assume at least 10 pixels overlap
PX=10

# Keep track of the best overlap height
PX_BEST=0

# The overlap diff must be as close to 0 as possible
PX_DIFF=100

# And keep track of the best result so far.
PX_DIFF_BEST=100

# The list of temp files created.
fileList="check1.png check2.png crop2.png"

usage () {
    echo "
Usages:
 ${0##*/} imgTop imgBot

 imgTop: The 'top' image. Height of imgTop does not matter but the 
         width must match the width of the second image.

 imgBot: The 'bottom' image. Same rules as 'imgTop'.

Output will be single image with a file name like:

 imgTop-imgBot-widthxheight.jpg
"
    exit
}

# Check a PX overlap value for a match
checkOverlap () {
    # Cut the overlap amount from the bottom of the top image.
    convert -gravity SouthWest -crop ${W1}x${PX}+0+0 "${1}" +repage check1.png
    # And the top of the bottom image
    convert -gravity NorthWest -crop ${W2}x${PX}+0+0 "${2}" +repage check2.png
    # Compare the two overlap sections
    PX_DIFF=`convert check1.png check2.png -compose Difference -composite -colorspace gray -format '%[fx:mean*100]' info:`
}
# We have a PX_BEST which is the size of the overlap, so crop
# this from top and bottom, then join
cropAndJoin () {
    # Crop the overlap from the bottom image
    H2Crop=$(($H2 - $PX_BEST))
    convert -gravity SouthWest -crop ${W2}x${H2Crop}+0+0 "${2}" +repage crop2.png
    # Join the original top with the cropped bottom
    convert -append "${1}" crop2.png merged.png
    echo ""
}

# clean up the temp images and rename the result.
cleanUp () {
    # Get the name of the orginal images
    tmp1=${1##*/}
    tmp2=${2##*/}
    # remove the file extensions
    tmp1=${tmp1%\.*}
    tmp2=${tmp2%\.*}
    # get the file path for the first image (assume second image is here too)
    tmpPath=${1%/*}
    if [ "$tmpPath" = "$1" ]
    then
        tmpPath="."
    fi
    # the name of the new, merged image
    H=`identify -format '%h' "merged.png"`
    merged="${tmpPath}/${tmp1}-${tmp2}-${W1}x${H}.png"
    # Remove the temp files
    for x in $fileList
    do
        if [ -f "${x}" ]
        then
            rm -f "${x}"
        fi
    done
    if [ -f "merged.png" ]
    then
        mv -f "merged.png" "${merged}"
        echo "
Merged file can be found here:
 ${merged}
"
    else
        echo "
Something went wrong. Maybe the images where not a match?
"
    fi
}

# Basic checks
if [ "$2" = "" ]
then
    usage
fi
if [ ! -f "$1" -o ! -f "$2" ]
then
    usage
fi

# The width and height of the images
W1=`identify -format '%w' "${1}"`
W2=`identify -format '%w' "${2}"`

# The width of the two images must match
if [ $W1 -ne $W2 ]
then
    echo "
Images are not the same width.
"
    exit
fi

# Need to know the height of the images too.
H1=`identify -format '%h' "${1}"`
H2=`identify -format '%h' "${2}"`

# Max height is need to make sure the loop does not go on forever
MAX=$H1

if [ $H1 -gt $H2 ]
then
    MAX=$H2
fi

echo -n "
Looking for a match point "

while [ $PX -lt $MAX ]
do
    echo -n "."
    checkOverlap "${1}" "${2}"
    if [ "$PX_DIFF" != "0" ]
    then
        PX_DIFF=${PX_DIFF%%.*}
    fi
    if [ $PX_DIFF -lt $PX_DIFF_BEST ]
    then
        PX_DIFF_BEST=$PX_DIFF
        PX_BEST=$PX
    fi
    # Check for a perfect match
    if [ $PX_DIFF -eq 0 ]
    then
        PX=$MAX
    else
        PX=$(($PX + 1))
    fi
done

# Check we have a good match, if not tell them.
if [ $PX_DIFF_BEST -gt $THRESHOLD ]
then
    echo "
Unable to find a good match point between the two images.

No merge performed.
"
    exit
fi

# We can assume a good match, try to merge the images.
cropAndJoin "${1}" "${2}"

cleanUp "${1}" "${2}"

echo "Done."
exit
2
27.01.2020, 20:28

Теги

Похожие вопросы