Перейти к содержимому
Compvision.ru

Доска почета


Popular Content

Showing most liked content on 02.04.2012 во всех областях

  1. 1 point
  2. 1 point
    Думаю эти ссылки будут интересны: https://mywebspace.wisc.edu/acahn/cs534webpage/dir/retinex.html http://cgm.computergraphics.ru/content/view/118 Матлабовский исходник с первой ссылки: % An implementation of the Retinex algorithm baised off a paper by Robert Sobol (2004). % It aproximates an ever decreasing spiral by moving in alternatingly horizontal and vertical % steps. This implementation goes arround five times at each level of the % spiral. The outer levels actualy represent closer relationships, as the % spiral tightens, because the mask values have propegated inwards, it % represents a more global operator ie longer distance relations. % Because our goal was to normalize images for facial recognition, not % preserve exact perception baised relationships for a human. Not much care % was put into the paramiters used. We simply tried a couple values and % used one that was "good enough". Similarly, not all of the math is % exactly faithful to the algorithm described by Sobol, some of it is % "pretty much right" and seems to give good results. This is particularly % true with rescaling the Retinex back to normal color space (from log % space). We simply "undid" the log operation and the results seemed good % in the grey space of images we are working on. function y = Retinex(inImage) inImage = double(inImage); [m,n] = size(inImage); for j=1:n % create a log version of input image for i=1:m if inImage(i,j) == 0 % aproximate 0 with a small number to avoid NaN issues L(i,j) = 0.00001; else L(i,j)=log(inImage(i,j)); end end end imCopy = L; Maximum = max(L(); % maximum intensity value in the image [sRow, sCol] = size(L); shift = 2^(fix(log2(min(sRow, sCol)))-1); % initial place to begin lastProduct = Maximum*ones(sRow, sCol); % initialize Last Product while (abs(shift) >= 1) % iterate intil spiral is one unit large for i = 1:5 currRow = 0; % move horizontaly currCol = shift; interProduct = lastProduct; if (currRow + currCol > 0) % bottom right spiral part interProduct((currRow+1):end, (currCol+1):end) = lastProduct(1:(end-currRow), 1:(end-currCol)) + imCopy((currRow+1):end, (currCol+1):end) - imCopy(1:(end-currRow), 1:(end-currCol)); % propigate inward (adding is log mulitply) else interProduct(1:(end+currRow), 1:(end+currCol)) = lastProduct((1-currRow):end, (1-currCol):end) + imCopy(1:(end+currRow),1:(end+currCol)) - imCopy((1-currRow):end, (1-currCol):end); % propigate inward (adding is log mulitply) end interProduct(interProduct > Maximum) = Maximum; % % if values excede the max image value, rescale product = (interProduct + lastProduct)/2; % average with the previous Product lastProduct = product; currRow = shift; % move verticly currCol = 0; interProduct = lastProduct; if (currRow + currCol > 0) % bottom right spiral part interProduct((currRow+1):end, (currCol+1):end) = lastProduct(1:(end-currRow), 1:(end-currCol)) + imCopy((currRow+1):end, (currCol+1):end) - imCopy(1:(end-currRow), 1:(end-currCol)); % propigate inward (adding is log mulitply) else interProduct(1:(end+currRow), 1:(end+currCol)) = lastProduct((1-currRow):end, (1-currCol):end) + imCopy(1:(end+currRow),1:(end+currCol)) - imCopy((1-currRow):end, (1-currCol):end); % propigate inward (adding is log mulitply) end interProduct(interProduct > Maximum) = Maximum; % if values excede the max image value, rescale product = (interProduct + lastProduct)/2; % average with the previous Product lastProduct = product; end shift = -shift/2; % tighten spiral end y = product; for j=1:n for i=1:m y(i,j)=exp(y(i,j)); % rescale output to be non logerithmic end end maxVal = max(max(y)); for j=1:n for i=1:m y(i,j)= y(i,j)/ maxVal; end end y = uint8(round(y * 255)); %figure, imshow(uint8(round(inImage))); This commented code shows the input %figure, imshow(y); and output images in the acgoritm [/code]
  3. 1 point
    Привет всем! Вот, попытался сделать пример вывода видео на форму. И, думаю, получилось Для того, что-бы скопировать IplImage в объект .NET типа Image, достаточно всего лишь одной строки: #include <opencv/cv.h> #include <opencv/highgui.h> ... using namespace System; using namespace System::Windows::Forms; using namespace System::Drawing::Imaging; using namespace System::Drawing; ... IplImage *iplImg; ... // Копирование IplImage в объект .NET типа Image Image ^image = gcnew Bitmap(iplImg->width, iplImg->height, iplImg->widthStep, PixelFormat::Format24bppRgb, IntPtr(iplImg->imageData)); ... или, с использованием класса Mat: cv::Mat imgMat; // Копирование cv::Mat в объект .NET типа Image Image ^img = gcnew Bitmap(imgMat.cols, imgMat.rows, imgMat.step, PixelFormat::Format24bppRgb, IntPtr(imgMat.data)); Чтобы вывести изображение на компоненту PictureBox, достаточно следующей строки в одном из методов вашей формы: this->pictureBox1->Image = image; Если вам нужен HBITMAP, то получить его можно следующим образом: Bitmap ^image = gcnew Bitmap(iplImg->width, iplImg->height, iplImg->widthStep, PixelFormat::Format24bppRgb, IntPtr(iplImg->imageData)); HBITMAP hb = (HBITMAP)image->GetHbitmap().ToPointer(); У меня вышеприведенные примеры отлично работают с OpenCV 2.2 в Visual Studio 2008/2010. К сообщению прилагаю проект простого видео плеера, написанного с помощью OpenCV 2.2 в Visual Studio 2008. Он может воспроизводить все типы видео, которые берет OpenCV и видео, захваченное с видеокамеры. Не судите строго за возможные несовершенства в коде Просто, я старался, что бы были основные функции плеера. Пояснения к проекту. Компиляция: Чтобы успешно скомпилировать проект, достаточно в опциях Visual Studio установить пути на OpenCV в следующем виде: %OPENCV_HOME%\include и %OPENCV_HOME%\lib Например, так: C:\OpenCV2.2\include и C:\OpenCV2.2\lib Другое: При создании проекта использовались следующие опции и установки. .NET Framework 3.5. General/Common Language Runtime Support: Common Language Runtime Support (/clr) C/C++/Advanced/Disable Specific Warnings: 4996;4793 Linker/Input/Additional Dependencies: opencv_core220d.lib opencv_highgui220d.lib opencv_imgproc220d.lib opencv_objdetect220d.lib Для версии Release: без "d" после 220. В компоненте PictureBox свойство SizeMode имеет значение Zoom, что позволяет сохранить оригинальное соотношение сторон кадра. Для визуализации кадров используется Tick таймера. При двойном щелчке по области отображения, происходит переход в полноэкранный режим и обратно. Надеюсь, пример кому-нибудь пригодится VideoOnForm.zip
×