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

Chemist

Пользователи
  • Количество публикаций

    22
  • Зарегистрирован

  • Посещение

Репутация

0 Новичек

О Chemist

  • Звание
    Бывалый
  1. Очистка памяти

    спасибо! ) как всегда невнимателен - нашел ошибку ))))
  2. Очистка памяти

    спасибо, за наводку но какой формат выбрать все перебрал (http://msdn.microsoft.com/ru-ru/library/system.drawing.imaging.pixelformat.aspx) подходит только Format8bppIndexed, но изображение вместо белого отдает в краснину
  3. Очистка памяти

    Перевел изображение в HSV, но перед выводом его в image оно не складывается private: System::Void MainForm_Shown(System::Object^ sender, System::EventArgs^ e) { //Cam->capture = cvCreateCameraCapture(CV_CAP_ANY); capture = cvCreateCameraCapture(CV_CAP_ANY); if (capture != 0) { //проверяем наличие подключенных камер this->label4->Visible = false; //скрываем надписьCybSys... SettingForm->label7->Text = "Видеокамера включена!"; frame = cvQueryFrame( capture ); imageRGB = cvCreateImage( cvSize(frame->width, frame->height), IPL_DEPTH_8U, 3 ); hsv = cvCreateImage( cvSize(frame->width, frame->height), IPL_DEPTH_8U, 3 ); h_plane = cvCreateImage( cvSize(frame->width, frame->height), IPL_DEPTH_8U, 1 ); s_plane = cvCreateImage( cvSize(frame->width, frame->height), IPL_DEPTH_8U, 1 ); v_plane = cvCreateImage( cvSize(frame->width, frame->height), IPL_DEPTH_8U, 1 ); h_range = cvCreateImage( cvSize(frame->width, frame->height), IPL_DEPTH_8U, 1 ); s_range = cvCreateImage( cvSize(frame->width, frame->height), IPL_DEPTH_8U, 1 ); v_range = cvCreateImage( cvSize(frame->width, frame->height), IPL_DEPTH_8U, 1 ); hsv_and = cvCreateImage( cvSize(frame->width, frame->height), IPL_DEPTH_8U, 1 ); // конвертируем в HSV cvCvtColor( frame, hsv, CV_BGR2HSV ); // разбиваем на отельные каналы cvCvtPixToPlane( hsv, h_plane, s_plane, v_plane, 0 ); if (OpenFileColor(R, G, == -1) { System::Windows::Forms::MessageBox::Show("Данные не были Прочитаны из файла!", "Ошибка чтения");} else { this->timer1->Start(); //запускаем таймер } } else { SettingForm->label7->Text = "Видеокамера не подключена!"; } } private: System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e) { myTrackbarHmin(SettingForm->hScrollBar1->Value); myTrackbarHmax(SettingForm->hScrollBar2->Value); myTrackbarHmin(SettingForm->hScrollBar3->Value); myTrackbarHmax(SettingForm->hScrollBar4->Value); myTrackbarHmin(SettingForm->hScrollBar5->Value); myTrackbarHmax(SettingForm->hScrollBar6->Value); //получаем кадр frame = cvQueryFrame( capture ); // конвертируем в HSV cvCvtColor( frame, hsv, CV_BGR2HSV ); // разбиваем на отельные каналы cvCvtPixToPlane( hsv, h_plane, s_plane, v_plane, 0 ); cvAnd(h_range, s_range, hsv_and); cvAnd(hsv_and, v_range, hsv_and); Bitmap^ bmpSetting = (gcnew System::Drawing::Bitmap(hsv_and->width, hsv_and->height, hsv_and->widthStep, System::Drawing::Imaging::PixelFormat::Format24bppRgb,(System::IntPtr)hsv_and->imageData)); SettingForm->pictureBox1->Image = bmpSetting;}[/code] п.с. на подписи скрол баров прошу внимания не обращать )
  4. Очистка памяти

    значит камера и подсветка сдесь особо не причем?
  5. Очистка памяти

    Да бы не городить новую тему, спрошу сдесь. Перевожу в в монохромное с выделением нужного цвета вот таким образом: IplImage* TreatmentImage::YellowInBlackAndWhite(IplImage* rgb ,int B, int G, int R){ int x, y; ptr = (uchar*)(rgb->imageData); for(x = 0; x<rgb->width-1; x++){ //преобразуем изображение с желтыми метками в монохромное for (y = 0; y<rgb->height-1; y++){ if ((ptr[3*x+y*rgb->widthStep] < && (ptr[3*x+1+y*rgb->widthStep] > G) && (ptr[3*x+2+y*rgb->widthStep] > R)) { ptr[3*x+y*rgb->widthStep] = 255; //H ptr[3*x+1+y*rgb->widthStep] = 255; //S ptr[3*x+2+y*rgb->widthStep] = 255; //V } else { ptr[3*x+y*rgb->widthStep] = 0; ptr[3*x+1+y*rgb->widthStep] = 0; ptr[3*x+2+y*rgb->widthStep] = 0; } } } return rgb; }[/code] прохо выделяется искомый цвет, и очень большое влияние оказывает внешнее освещение. Подскажите как тут быть, менять камеру (на подобии Logitech Webcam C600) или городить подсветку?
  6. Очистка памяти

    Вроде то же разобрался, перенес за цикл.
  7. Очистка памяти

    Спасибо, с этим вроде разобрался, но теперь возникает другое исключение. В ходе работы вот в этой строчке: imageRGB = cvCreateImage( cvSize(frame->width, frame->height), IPL_DEPTH_8U, 3 );
  8. Очистка памяти

    забыл добавить: пишу в VS C++ 2008
  9. Очистка памяти

    Без cvReleaseImage программа через некоторое время вылетает, но вся проблема в том что после прописания вот этой строчки -cvReleaseImage( &ImageRGB);, компилятор ругается - error C2664: cvReleaseImage: невозможно преобразовать параметр 1 из 'cli::interior_ptr<Type>' в 'IplImage **'
  10. ImageData

    все оказалось проще ) ptr[3*x+y*frame->widthStep] // Синий ptr[3*x+1+y*frame->widthStep] // Зеленый ptr[3*x+2+y*frame->widthStep] // Красный вот такое условие для нахождение красного цвета у меня получилось: if ((ptr[3*x+y*frame->widthStep] < 40) && (ptr[3*x+1+y*frame->widthStep] < 30) && (ptr[3*x+2+y*frame->widthStep] > 150))
  11. ImageData

    про HSV уже гуглил, видел модели и прочее. не пойму в каких пределах опрашивать: от 0 до 255 все или H:0-360, S:0-1, V:0-1? ptr[3*x+y*frame->widthStep] //H ptr[3*x+1+y*frame->widthStep] //S ptr[3*x+2+y*frame->widthStep] //V
  12. ImageData

    Не получается подобрать красный цвет, использую вот такой код: for(x = 0; x<frame->width; x++){ for (y = 0; y<frame->height; y++){ if (((ptr[3*x+y*frame->widthStep] > this->hScrollBar1->Value-10) && (ptr[3*x+y*frame->widthStep] < this->hScrollBar1->Value+10)) && ((ptr[3*x+1+y*frame->widthStep] > this->hScrollBar2->Value-10) && (ptr[3*x+1+y*frame->widthStep] < this->hScrollBar2->Value+10)) && ((ptr[3*x+2+y*frame->widthStep] > this->hScrollBar3->Value-10) && (ptr[3*x+2+y*frame->widthStep] < this->hScrollBar3->Value+10))) { ptr[3*x+y*frame->widthStep] = 255; //H ptr[3*x+1+y*frame->widthStep] = 255; //S ptr[3*x+2+y*frame->widthStep] = 255; //V } else { ptr[3*x+y*frame->widthStep] = 0; ptr[3*x+1+y*frame->widthStep] = 0; ptr[3*x+2+y*frame->widthStep] = 0; } } } Для простоты подбора использую вот такую картинку:
  13. OpenCV поиск синего шарика

    Возникла некая проблемка, компилирую вот этот код в vs C++ 2008 // Поиск.cpp: главный файл проекта. #include "stdafx.h" #include "cv.h" #include "highgui.h" #include <stdio.h> #include <ctype.h> void FindBall(IplImage* Img); void Counter(IplImage* img); CvPoint2D32f center; float radius; long pointer=0; int main( int argc, char** argv ) { CvCapture* capture = 0; capture = cvCreateCameraCapture(CV_CAP_ANY); cvNamedWindow( "Demo", 1 ); for(; { IplImage* frame = 0; int i, k, c; frame = cvQueryFrame( capture ); if( !frame ) break; FindBall(frame); cvShowImage( "Demo", frame ); c = cvWaitKey(50); if( (char)c == 27 ) break; pointer++; } cvWaitKey(0); cvReleaseCapture( &capture ); cvDestroyWindow("Demo"); return 0; } void FindBall(IplImage* Img) { IplImage* Image=cvCreateImage( cvGetSize(Img), 8, 3 ); cvCopy(Img,Image); //Теперь необходимо получить доступ к всем пикселям. uchar* ptr1; ptr1 = (uchar*) (Image->imageData ); int i,j; for(i=0;i<Img->height;i++) for(j=0;j<Img->width;j++) { //R > 1.5*G, R > 2*B if (ptr1[j*3+2+i*Image->widthStep]>1.5*ptr1[j*3+1+i*Image->widthStep] && ptr1[j*3+2+i*Image->widthStep]>2*ptr1[j*3+i*Image->widthStep]) { ptr1[j*3+i*Image->widthStep]=255; ptr1[j*3+1+i*Image->widthStep]=255; ptr1[j*3+2+i*Image->widthStep]=255; } else { ptr1[j*3+i*Image->widthStep]=0; ptr1[j*3+1+i*Image->widthStep]=0; ptr1[j*3+2+i*Image->widthStep]=0; } } //Выделение контуров и поиск наибольшего контура Counter(Image); if (center.x>-1) { CvPoint p; p.x=center.x; p.y=center.y; cvCircle( Img, p, radius, CV_RGB(255,0,0), 3, 8, 0 ); } cvReleaseImage( &Image ); } void Counter(IplImage* img) { IplImage* img_gray= cvCreateImage( cvSize(img->width,img->height), 8, 1); CvSeq* contours = 0; CvMemStorage* storage = cvCreateMemStorage(0); cvCvtColor( img, img_gray, CV_BGR2GRAY ); cvFindContours( img_gray, storage, &contours, sizeof(CvContour), CV_RETR_LIST , CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0) ); CvSeq* h_next=0; //Поиск максимального контура for( CvSeq* c=contours; c!=NULL; c=c->h_next ) { if (c!=contours) { //Проверяем какой контур больше if (h_next->total>=c->total) { h_next->h_next=h_next->h_next->h_next; continue; } } h_next=c; } center.x=-1; if (h_next->total<200) return;//нет мяча - слишком маленькие контуры cvDrawContours( img, h_next, CV_RGB(255,0,0), CV_RGB(0,255,0),2, 2, CV_AA, cvPoint(0,0) ); //Минимальная окружность cvMinEnclosingCircle(h_next,&center,&radius); cvReleaseMemStorage( &storage); cvReleaseImage( &img_gray ); } [/code] Код компилируется после создания окна вылезает окно, в нем написано "Дополнительные сведения: В экземпляре объекта не задана ссылка на объект." и указывает с начало на эту строчку: if (h_next->total<200) return;//нет мяча - слишком маленькие контуры потом, если её за коментить то указывает на вот эту строчку: cvMinEnclosingCircle(h_next,&center,&radius); и выдает следующую надпись"Дополнительные сведения: Внешний компонент создал исключение" В чем может быть проблема?
×