Ejemplo n.º 1
0
void camera_straighten_display(int num, char* window_name) {
	int c;
	IplImage* color_img;
	CvCapture* cv_cap = cvCaptureFromCAM(num);
	cvNamedWindow("Video", 0); // create window
	for(;;) {
		color_img = cvQueryFrame(cv_cap); // get frame
		if(color_img != 0) {
			Mat cam_mat(color_img);
			Mat result;
			cam_mat.copyTo(result);

			Straightener straight(640, 480);

			if(straight.doAll(cam_mat, result)) {
				imshow("Video", result); // show frame
			}
		}
		c = cvWaitKey(10); // wait 10 ms or for key stroke
		if(c == 27)
			break; // if ESC, break and quit
	}
	/* clean up */
	cvReleaseCapture( &cv_cap );
	cvDestroyWindow("Video");
}
Ejemplo n.º 2
0
void camera_HUE_display(int num) {
	int c;
	IplImage* color_img;
	CvCapture* cv_cap = cvCaptureFromCAM(num);
	cvNamedWindow("Video", 0); // create window
	for(;;) {
		color_img = cvQueryFrame(cv_cap); // get frame
		if(color_img != 0) {
			Mat cam_mat(color_img);
			Mat frameBGR;
			cam_mat.copyTo(frameBGR);
			Mat frameHSV;
			cvtColor(frameBGR, frameHSV, CV_BGR2HSV);
			Mat Hue = Mat(frameHSV.rows, frameHSV.cols, CV_8UC1);
			//Hue.create(frameHSV.size(), frameHSV.depth());
			int ch[] = { 1, 0 };
			mixChannels( &frameHSV, 1, &Hue, 1, ch, 1 );
			imshow("Video", Hue);
			c = cvWaitKey(10); // wait 10 ms or for key stroke
			if(c == 27) {
				break; // if ESC, break and quit
			}
		}
		c = cvWaitKey(10); // wait 10 ms or for key stroke
		if(c == 27)
			break; // if ESC, break and quit
	}
	/* clean up */
	cvReleaseCapture( &cv_cap );
	cvDestroyWindow("Video");
}
Ejemplo n.º 3
0
Archivo: cam.c Proyecto: HARM67/Fdf
t_vec4				do_cam(t_app *app, t_vec4 v)
{
	t_vec4		rt;
	t_matrix4x4	mat;

	mat = cam_mat(app);
	rt = muli_mat4x4_vec4(mat, v);
	return (rt);
}
Ejemplo n.º 4
0
void		do_transform(t_app *app, t_obj *obj, t_matrix4x4 mat)
{
	unsigned int	i;
	float			proj;

	i = 0;
	proj = app->scene.cam.proj;
	obj->mat = scale_mat(obj->scale);
	obj->mat = muli_mat4x4(rot_y_mat(obj->rot.y), obj->mat);
	obj->mat = muli_mat4x4(rot_x_mat(obj->rot.x), obj->mat);
	obj->mat = muli_mat4x4(rot_z_mat(obj->rot.z), obj->mat);
	obj->mat = muli_mat4x4(translate_mat(obj->pos), obj->mat);
	obj->mat = muli_mat4x4(mat, obj->mat);
	obj->mat = muli_mat4x4(cam_mat(app), obj->mat);
	while (i < obj->nbr_vecs)
	{
		obj->vecs[i] = muli_mat4x4_vec4(obj->mat, obj->vecs_orig[i]);
		i++;
	}
}
Ejemplo n.º 5
0
/** Create a RIB compatible representation of a Maya pfxToon node as RiCurves.
 */
liqRibPfxToonData::liqRibPfxToonData( MObject pfxToon )
  : nverts(),
    CVs(),
    curveWidth(),
    cvColor(),
    cvOpacity()
{
  LIQDEBUGPRINTF( "-> creating pfxToon curves\n" );
  MStatus status( MS::kSuccess );

  // Update the pfxToon node with the renderCamera's position
  // otherwise the resulting outline might be incorrect
  MDagPath cameraPath;
  MSelectionList camList;
  camList.add( liqglo_renderCamera );
  camList.getDagPath( 0, cameraPath );
  MMatrix cam_mat( cameraPath.inclusiveMatrix() );
  MFnDependencyNode pfxToonNode( pfxToon );
  pfxToonNode.findPlug( "cameraPointX" ).setValue( cam_mat( 3, 0 ) );
  pfxToonNode.findPlug( "cameraPointY" ).setValue( cam_mat( 3, 1 ) );
  pfxToonNode.findPlug( "cameraPointZ" ).setValue( cam_mat( 3, 2 ) );


  MFnPfxGeometry pfxtoon( pfxToon, &status );

  if ( status == MS::kSuccess ) 
	{
    MRenderLineArray profileArray;
    MRenderLineArray creaseArray;
    MRenderLineArray intersectionArray;

    bool doLines          = true;
    bool doTwist          = false;
    bool doWidth          = true;
    bool doFlatness       = false;
    bool doParameter      = false;
    bool doColor          = true;
    bool doIncandescence  = false;
    bool doTransparency   = true;
    bool doWorldSpace     = false;

    status = pfxtoon.getLineData( profileArray, creaseArray, intersectionArray, doLines, doTwist, doWidth, doFlatness, doParameter, doColor, doIncandescence, doTransparency, doWorldSpace );

    if ( status == MS::kSuccess ) 
    {
      // Het the lines and fill the arrays.
      ncurves = profileArray.length();
      {
        MFnDependencyNode pfxNode( pfxToon );
        MString info( "[liquid] pfxToon node " );
        info += pfxNode.name() + " : " + ncurves + " curves.";
        cout << info << endl << flush;
      }

      unsigned totalNumberOfVertices( 0 );

      if ( ncurves > 0 ) 
      {
        nverts = shared_array< RtInt >( new RtInt[ ncurves ] );

        // Calculate storage requirments.
        // This is a lot more efficient than all those reallocs()
        // (or resize()s if we used a vector) that were done before
        // in the main loop below.
        for ( unsigned i( 0 ); i < ncurves; i++ ) 
				{
          MRenderLine theLine( profileArray.renderLine( i, &status ) );
          if ( MS::kSuccess == status ) 
					{
            MVectorArray vertices( theLine.getLine() );
            totalNumberOfVertices += vertices.length();
          }
        }

        // Allocate memory
        CVs = shared_array< RtFloat >( new RtFloat[ totalNumberOfVertices * 3 ] );
        if ( !CVs ) 
				{
          MString err( "liqRibPfxToonData failed to allocate CV memory!" );
          cout << err << endl << flush;
          throw( err );
          return;
        }

        curveWidth = shared_array< RtFloat >( new RtFloat[ totalNumberOfVertices ] );
        if ( !curveWidth ) 
				{
          MString err( "liqRibPfxToonData failed to allocate per vertex width memory!" );
          cout << err << endl << flush;
          throw( err );
          return;
        }

        cvColor = shared_array< RtFloat >( new RtFloat[ totalNumberOfVertices * 3 ] );
        if ( !cvColor ) 
				{
          MString err( "liqRibPfxToonData failed to allocate CV color memory!" );
          cout << err << endl << flush;
          throw(err);
          return;
        }

        cvOpacity = shared_array< RtFloat >( new RtFloat[ totalNumberOfVertices * 3 ] );
        if ( !cvOpacity ) 
				{
          MString err("liqRibPfxToonData failed to allocate CV opacity memory !");
          cout << err << endl << flush;
          throw( err );
          return;
        }

        RtFloat* cvPtr;
        RtFloat* widthPtr;
        RtFloat* colorPtr;
        RtFloat* opacityPtr;

        totalNumberOfVertices = 0;

        for ( unsigned i( 0 ); i < ncurves; i++ ) 
        {
          MRenderLine theLine( profileArray.renderLine( i, &status ) );

          if ( MS::kSuccess == status ) {

            const MVectorArray& vertices(           theLine.getLine() );
            const MDoubleArray& width(              theLine.getWidth() );
            const MVectorArray& vertexColor(        theLine.getColor() );
            const MVectorArray& vertexTransparency( theLine.getTransparency() );

            //cout <<"line "<<i<<" contains "<<vertices.length()<<" vertices."<<endl;
            //cout <<vertexColor<<endl;

            nverts[i] = vertices.length();
            totalNumberOfVertices += vertices.length();

            cvPtr      = CVs.get()        + ( totalNumberOfVertices * 3 - nverts[ i ] * 3 ) ;
            widthPtr   = curveWidth.get() + ( totalNumberOfVertices     - nverts[ i ] ) ;
            colorPtr   = cvColor.get()    + ( totalNumberOfVertices * 3 - nverts[ i ] * 3 ) ;
            opacityPtr = cvOpacity.get()  + ( totalNumberOfVertices * 3 - nverts[ i ] * 3 ) ;

            for ( unsigned vertIndex( 0 ); vertIndex < vertices.length(); vertIndex++ ) 
            {
              *cvPtr++      = ( RtFloat ) vertices[ vertIndex ].x;
              *cvPtr++      = ( RtFloat ) vertices[ vertIndex ].y;
              *cvPtr++      = ( RtFloat ) vertices[ vertIndex ].z;

              *widthPtr++   = ( RtFloat )width[ vertIndex ];

              *colorPtr++   = ( RtFloat )vertexColor[ vertIndex ].x ;
              *colorPtr++   = ( RtFloat )vertexColor[ vertIndex ].y ;
              *colorPtr++   = ( RtFloat )vertexColor[ vertIndex ].z ;

              *opacityPtr++ = ( RtFloat )( 1.0f - vertexTransparency[ vertIndex ].x ) ;
              *opacityPtr++ = ( RtFloat )( 1.0f - vertexTransparency[ vertIndex ].y ) ;
              *opacityPtr++ = ( RtFloat )( 1.0f - vertexTransparency[ vertIndex ].z ) ;
            }
          }
        }

        // Store for output
        liqTokenPointer points_pointerPair;
        if ( !points_pointerPair.set( "P", rPoint, true, false, totalNumberOfVertices ) ) 
				{
          MString err( "liqRibPfxToonData: liqTokenPointer failed to allocate CV memory !" );
          cout << err << endl;
          throw(err);
          return;
        }
        points_pointerPair.setDetailType( rVertex );
        points_pointerPair.setTokenFloats( CVs );
        tokenPointerArray.push_back( points_pointerPair );

        // Store width params
        liqTokenPointer width_pointerPair;
        if ( !width_pointerPair.set( "width", rFloat, true, false, totalNumberOfVertices ) ) 
				{
          MString err("liqRibPfxToonData: liqTokenPointer failed to allocate width memory !");
          cout <<err<<endl;
          throw(err);
          return;
        }
        width_pointerPair.setDetailType( rVarying );
        width_pointerPair.setTokenFloats( curveWidth );
        tokenPointerArray.push_back( width_pointerPair );

        // Store color params
        liqTokenPointer color_pointerPair;
        if ( !color_pointerPair.set( "pfxToon_vtxColor", rColor, true, false, totalNumberOfVertices ) ) 
				{
          MString err("liqRibPfxToonData: liqTokenPointer failed to allocate color memory !");
          cout <<err<<endl;
          throw(err);
          return;
        }
        color_pointerPair.setDetailType( rVertex );
        color_pointerPair.setTokenFloats( cvColor );
        tokenPointerArray.push_back( color_pointerPair );

        // Store opacity params
        liqTokenPointer opacity_pointerPair;
        if ( !opacity_pointerPair.set( "pfxToon_vtxOpacity", rColor, true, false, totalNumberOfVertices ) ) 
				{
          MString err("liqRibPfxToonData: liqTokenPointer failed to allocate opacity memory !");
          cout <<err<<endl<<flush;
          throw(err);
          return;
        }
        opacity_pointerPair.setDetailType( rVertex );
        opacity_pointerPair.setTokenFloats( cvOpacity );
        tokenPointerArray.push_back( opacity_pointerPair );

        addAdditionalSurfaceParameters( pfxToon );

      }
    }
  }
}
Ejemplo n.º 6
0
void camera_contours_display(int num, Straightener & straight) {
	int c;
		IplImage* color_img;
		CvCapture* cv_cap = cvCaptureFromCAM(num);
		cvNamedWindow("Video", 0); // create window
		resizeWindow("Video", 700,700);
		for(;;) {
			color_img = cvQueryFrame(cv_cap); // get frame
			if(color_img != 0) {
				Mat cam_mat(color_img);
				Mat result;
				cam_mat.copyTo(result);

				if(straight.doAll(cam_mat, result)) {
					///Apply blur
					blur(result, result, Size(3,3));
					///Apply Canny to destination Matrix
					Canny(result, result, 50, 50, 3);
					/// Vectors for storing contours
					vector<vector<Point> > contours; //contours of the paper sheet
					vector<vector<Point> > approx_contours; //approx contours of the paper sheet
					vector<Vec4i> hierarchy;
					int erosion_type = 2;
					int erosion_size = 3;
					Mat element = getStructuringElement(erosion_type,
														Size( 2*erosion_size + 1, 2*erosion_size+1),
														Point( erosion_size, erosion_size));
					dilate(result, result, element);
					/// Cut 20 px from each side to avoid paper borders detection
					result = result(Rect(10, 10, result.cols-20, result.rows-20));
					findContours(result, contours, hierarchy, CV_RETR_CCOMP, CV_CHAIN_APPROX_NONE, Point(0, 0));
					/// Draw contours
					Mat drawing = Mat::zeros( result.size(), CV_8UC3 );
					/// https://github.com/Itseez/opencv/blob/master/samples/cpp/contours2.cpp
//					approx_contours.resize(contours.size());
					for(unsigned int i = 0; i < contours.size(); i++) {
						/// Area of more than 20 and no parent
						if(contourArea(contours[i]) > 20 && hierarchy[i][3] == -1) {
							vector<Point> tmp_contour;
							approxPolyDP(Mat(contours[i]), tmp_contour, 3, true);
							approx_contours.push_back(tmp_contour);
						}
					}
					for(unsigned int i=0; i < approx_contours.size(); i++) {
						Scalar color;
						if(approx_contours[i].size() == 4) {
							color = Scalar( 255, 255, 255);
							drawContours( drawing, approx_contours, i, color, 1, 8, NULL, 0, Point() );
						}
						else {
							color = Scalar( 0, 255, 0);
							drawContours( drawing, approx_contours, i, color, 1, 8, NULL, 0, Point() );
						}
					}
					imshow("Video", drawing);
				}
			}
			c = cvWaitKey(10); // wait 10 ms or for key stroke
			if(c == 27)

				break; // if ESC, break and quit
		}
		/* clean up */
		cvReleaseCapture( &cv_cap );
		cvDestroyWindow("Video");
}